Closed
Description
Symfony version(s) affected: 3.4.31 (probably other versions too)
Description
Tags on cached items might be randomly lost when using TagAwareAdapter with RedisAdapter as items pool and having Redis set with eviction policy that evicts keys. Because of that, affected items can't be invalidated using tags but are still treated as valid items (cache hit) when retrieved from cache.
How to reproduce
- Create item-tags pair in Redis using
TagAwareAdapter
, for example:"something:my-great-item"
"something:\x00tags\x00my-great-item"
- Fetch it using
TagAwareAdapter
- returned CacheItem has
isHit
set totrue
andgetPreviousTags
returns tags
- returned CacheItem has
- Manually delete
tag
from pair to simulate eviction:DEL "something:\x00tags\x00my-great-item"
- Fetch it using
TagAwareAdapter
- returned CacheItem has
isHit
set totrue
andgetPreviousTags
returns empty tags, making it impossible to invalidate
- returned CacheItem has
Possible Solution
If I am correct, cache items are always stored in item-tags pairs, regardless of item having or not having tags. Based on that, when item is fetched and does not have tags pair it should be deleted from cache and treated as cache miss.