Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Missing cache item tags with TagAwareAdapter and Redis eviction policy  #33953

Closed
@v-m-i

Description

@v-m-i

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

  1. Create item-tags pair in Redis using TagAwareAdapter, for example:
    • "something:my-great-item"
    • "something:\x00tags\x00my-great-item"
  2. Fetch it using TagAwareAdapter
    • returned CacheItem has isHit set to true and getPreviousTags returns tags
  3. Manually delete tag from pair to simulate eviction:
    • DEL "something:\x00tags\x00my-great-item"
  4. Fetch it using TagAwareAdapter
    • returned CacheItem has isHit set to true and getPreviousTags returns empty tags, making it impossible to invalidate

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions