Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | 3.3.4 |
Problem description
We are experiencing an issue with Redis + TagAwareAdapter where in some cases the cache does not invalidate. In regular situations the cache is cleared properly as far as we can tell, but it seems in some edge cases it is not.
In these cases, we need to clean out the whole cache using clear()
on the pool.
Troubleshooting steps
We use the same pool-adapter for the tag-item as the cache-item itself. When the issue appears, i ask the items in the pool using redis-cli
:
127.0.0.1:6379> keys *nl*GpSchedule* 1) "sitecache.1.nl:U_1_S_2699916618_module_GpSchedule_"
2) "sitecache.1.nl:A_1_S_2699916618_module_GpSchedule_"
3) "sitecache.1.nl:U_1_S_1564297934_module_GpSchedule_"
4) "sitecache.1.nl:\x00tags\x00U_1_S_1564297934_module_GpSchedule_"
As you can see there is no \x00tags\x00 item at all. Then i run clear()
on the pool:
127.0.0.1:6379> keys *nl*GpSchedule*
1) "sitecache.1.nl:U_1_S_2699916618_module_GpSchedule_"
2) "sitecache.1.nl:\x00tags\x00U_1_S_2699916618_module_GpSchedule_"
3) "sitecache.1.nl:A_1_S_2699916618_module_GpSchedule_"
4) "sitecache.1.nl:\x00tags\x00A_1_S_2699916618_module_GpSchedule_"
I get both the \x00tags\x00 pool-item as the main item.
My idea
As far as I understand the code.. In the createCacheItem
closure in TagAwareAdapter
the expiry/defaultLifetime of the tag-item is the same as that of the cache-item. This means that if Redis starts expiring keys (which apparently it does randomly) it might select the 'tags' item as a victim, leaving the main item.
As the code assumes the item is not expired at all whenever the tags item does not exist, we are never able to expire it anymore.
Request
I chatted about this with @nicolas-grekas on Slack and I now doubt I understand the tag code properly.
- Am i correct to think that whenever we create a cache item with tags, it also creates the cache-item with the
\x00tags\x00
prefix of the id? - Is there any troubleshooting i can do to see which tags are linked to an item if the issue occurs again?