Skip to content

[Cache] Fix example for using cache tags with TagAwareCacheInterface #12181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

pavelmaca
Copy link
Contributor

Using Cache Tags section has invalid example. Should use TagAwareCacheInterface.

@pavelmaca pavelmaca changed the title Update cache.rst [Cache] Fix example for using cache tags with TagAwareCacheInterface Aug 15, 2019
@OskarStark
Copy link
Contributor

@Nyholm could you please verify this docs change? Thank you 😃

Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pavelmaca for the change and @Nyholm for the review 👍

@Nyholm
Copy link
Member

Nyholm commented Aug 16, 2019

Oh wait. I will review it shortly.

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,
Thank you for this PR. The TagAwareCacheInterface is an interface for the cache adapter. What we get passed to our function is a cache item.

@Nyholm
Copy link
Member

Nyholm commented Aug 16, 2019

👎 (to be clear)

@OskarStark
Copy link
Contributor

@pavelmaca can you explain a bit why you did this change or which error do you have?

@Nyholm
Copy link
Member

Nyholm commented Aug 16, 2019

I did find a bug when testing this out. Maybe that was what @pavelmaca experienced?

symfony/symfony#33201

cache.rst Outdated

$value0 = $pool->get('item_0', function (ItemInterface $item) {
$value0 = $pool->get('item_0', function (TagAwareCacheInterface $item) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the $pool that should be a TagAwareCacheInterface.

@pavelmaca could you update this PR a little? Could you wrap this code into a function or a class and make sure $pool is a TagAwareCacheInterface?

@Nyholm
Copy link
Member

Nyholm commented Aug 16, 2019

More info here: symfony/symfony#33201

@pavelmaca
Copy link
Contributor Author

@Nyholm Your findings are correct in symfony/symfony#33201

Updated doc with function and autowired $pool


$value0 = $pool->get('item_0', function (ItemInterface $item) {
$item->tag(['foo', 'bar'])
// using autowiring
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// using autowiring

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oscar, what do you think? Should we create a class and use constructor injection or is that overkill?

It would be more clear since injection to a function is generally only used with controllers.

$value0 = $pool->get('item_0', function (ItemInterface $item) {
$item->tag(['foo', 'bar'])
// using autowiring
public function listProducts(TagAwareCacheInterface $pool)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update $pool to $myCachePool to match the config below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a more generic name than listProducts. Maybe foo?

@OskarStark
Copy link
Contributor

Oscar, what do you think? Should we create a class and use constructor injection or is that overkill?

I think this would make sense in this case, otherwise this must be a tage with controller arguments tag 👍

👍 for a class + injection

@javiereguiluz
Copy link
Member

I tried to merge this but I couldn't fix the conflicts ... so I created in #12398 a new pull request with these changes and all the other changes requested by Tobias. @pavelmaca I kept your original commit, so you'll get credit for this contribution. Thanks.

javiereguiluz added a commit that referenced this pull request Oct 1, 2019
…, javiereguiluz)

This PR was merged into the 4.3 branch.

Discussion
----------

[Cache] Improved the example about cache tags

This continues the work started in #12181.

Commits
-------

f9d438f Fixed code
2651f92 [Cache] Improved the example about cache tags
ce0c625 [Cache] Fix example for using cache tags with TagAwareCacheInterface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants