-
-
Notifications
8000
You must be signed in to change notification settings - Fork 9.6k
[CACHE] Never hits cache with TagAwareAdapter #54097
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
Comments
@nicolas-grekas Hello! Very sorry for bothering you. Could you have a look at this please? Could be cause of #53846 |
Can you try to figure out what happens? |
I'm trying, but tbh i'm a little bit confused with TagAwareAdapter code :) |
I don't think |
Well, i compared with my current 5.4.34 and I agree that behaviour of |
wdyt? Saving and retrieving tags as associative array . Comparing is correct after this because we not losing these 6 random_bytes which are version. |
Can I up this? Still thinks this is pretty critical |
+1 |
1 similar comment
+1 |
I would need more insights to be of any help. I tried your reproducer @AtCliffUnderline but I miss an observer to tell which behavior is wrong. If I Note that your wiring is really strange: a RedisTagAwareAdapter inside a TagAwareAdapter? |
@nicolas-grekas here is an other example, maybe even simpler to reproduce I have the same issue with this config based on the docs of the chain adapter with redis tag aware i guess (should not matter at all, looks like a cache tag problem anyways) services:
redis.provider.one:
class: Redis
factory: [ 'Symfony\Component\Cache\Adapter\RedisTagAwareAdapter', 'createConnection' ]
arguments:
- '%env(CACHE_REDIS_DSN_DEFAULT)%/6'
redis.provider.two:
class: Redis
factory: [ 'Symfony\Component\Cache\Adapter\RedisTagAwareAdapter', 'createConnection' ]
arguments:
- '%env(WEBSHOP_REDIS_DSN_FLATDATA)%'
- { retry_interval: 1, timeout: 10 }
'cache.adapter.redis.one':
parent: 'cache.adapter.redis_tag_aware'
arguments:
$redis: '@redis.provider.one'
$namespace: 'fancy_namespace'
'cache.adapter.redis.two':
parent: 'cache.adapter.redis_tag_aware'
arguments:
$redis: '@redis.provider.two'
$namespace: 'other_fancy_namespace'
framework:
cache:
pools:
fancy_cache_pool:
default_lifetime: 31536000 # One year
adapters:
- cache.adapter.redis.one
- cache.adapter.redis.two
tags: true
If you run this twice, it is build twice (or more) $myCachedData = $this->cachePool->get(
key: 'fancy_cache_key',
callback: function (ItemInterface $item): string {
dump($item->getKey() . ' was build ');
$item->tag(['tag1', 'tag2']);
return 'my cached value';
});
$myCachedData = $this->cachePool->get(
key: 'fancy_cache_key_2',
callback: function (ItemInterface $item): string {
dump($item->getKey() . ' was build ');
// $item->tag(['tag1', 'tag2']); <-- no tags
return 'my cached value';
});
possible cause:
I hope this may help to fix this |
Can you please put the reproducer in a small app I could clone ? |
Of cause, give me a minute or 10 ;) |
@nicolas-grekas here we go https://github.com/Fahl-Design/cache-issue-reproducer *edit: inside redis: "tags" is always set as a key suffix NOT prefix https://github.com/Fahl-Design/cache-issue-reproducer edit: updated to make it more visible and symfony v7 as well can be reproduces in v6.4 and v7.0 |
Thanks for the reproducer app @Fahl-Design Now I'm confused. Is this issue new? For some reason, I had the understanding that this was introduced in 6.4.4, but it's not, right? The reproducer behaves the same with 7.0.0 or 7.0.4, or I missed something. Could any of you tell me why you're putting a RedisTagAwareAdapter in a chain that's then given to TagAwareAdapter? This doesn't make any sense to me and that'd the other thing I'd need to clarify. |
You'r welcome, I found this issue mainly by accident ;) I use 6.4 in an app and this was my first time using a tagged cache pool.
maybe the yaml don't make it clear ;) ...
redis.provider.two:
class: Redis
factory: [ 'Symfony\Component\Cache\Adapter\RedisTagAwareAdapter', 'createConnection' ]
...
I guess that's from my understanding of the docs isn't that how the pools should be set up to work?^^ I attempt is to setup a cache pool with tags in a chain to fill a second redis instance for an other app. when you run I had a look at the corresponding code but man, that's not easy to follow (and when tags are involved) |
OK, I think I get what we want to achieve. There are two aspects here: Why does it not work as is?My guess is that there is some bad interaction between RedisTagAwareAdapter and TagAwareAdapter. We could try to understand why and figure out a way around, but the wiring doesn't make sense in the first place to me. This leads to the second point; What are you trying to achieve?My guess is you're trying to have a cache that stores things locally (ArrayAdapter) on top of a remote cache storage (Redis), and you want that chain to be able to manage tags. You can achieve this immediately by not using RedisTagAwareAdapter in the chain. Just use a regular RedisAdapter. This means the storage layout is going to use versioned tags instead of tag relationships (what RedisTagAwareAdapter manages). Tag relationships require more storage but save a few roundtrips. If you don't have an objective reason to use them, versioned tags are really good anyway. Then remains the question of wiring an ArrayAdapter on top of a RedisTagAwareAdapter. I think we would need a TagAwareChainAdapter and TagAwareArrayAdapter for this. Or another better idea :) |
I will open a new issue with a new title. In my case, and the reproducer code, there are no array adapters |
Yes, the array adapter is not the issue so it doesn't matter. |
I apologize for not responding in this issue. Indeed, it makes no sense to use RedisTagAwareAdapter inside TagAwareAdapter, changing it to RedisAdapter made the problem go away, thanks Sorry for going off-topic though, I really wanted to clarify, right now I'm in the process of upgrading from version 5.4 to version 6.4, and I can't understand at all, is it so necessary to make a second request to the pool (in my case to Redis) https://github.com/symfony/cache/blob/6.4/Adapter/TagAwareAdapter.php#L180 ? This has added 4-5 ms of response time in my project as I am actively using cache. Trying to find what to do, is the only option for me right now is to use 6.1.11? |
There are two storage strategies with redis:
Chose one, just don't mix both :) |
@nicolas-grekas thanks for clarification, sounds good to me |
Hey, thanks for your report! |
Friendly ping? Should this still be open? I will close if I don't hear anything. |
Symfony version(s) affected
6.4.4
Description
A bit similar to #53825
As in the code below, there is fetching several keys with
mget
. Keys are already exists in database. First fetch of keys withmget
retrieves them all and create good$bufferedItems
.But after that

getTagVersion
gets wrong tag (screenshot) and unseting them all (TagAwareAdapter.php:191). This bad tag have been stored by this adapter.And after unset them all it creates items with hit: false.
How to reproduce
Possible Solution
No response
Additional Context
Chain adapter is not really needed here. But this is my production setup.
Seems kinda critical imho
The text was updated successfully, but these errors were encountered: