TagsBundle icon indicating copy to clipboard operation
TagsBundle copied to clipboard

Missing expire/TTL on Redis keys

Open fredriktid opened this issue 4 years ago • 4 comments

When inspecting Redis keys from this bundle they're missing expiration/TTL:

$ redis-cli -n 1
> TTL namespace:tag-content-15681
(integer) -1

To avoid maxing out Redis memory with the "volatile-lru" eviction strategy one can define a "default_lifetime" in app/config/cache_pool/cache.redis.yml .

services:
    cache.redis:
        class: Symfony\Component\Cache\Adapter\TagAware\RedisTagAwareAdapter
        parent: cache.adapter.redis
        tags:
            - name: cache.pool
              clearer: cache.app_clearer
              provider: 'redis://%cache_dsn%?timeout=5&read_timeout=10'
              namespace: '%cache_namespace%'
              default_lifetime: 36000 # 10 hours

volatile-lru states that:

evict keys by trying to remove the less recently used (LRU) keys first, but only among keys that have an expire set, in order to make space for the new data added.

Expected behaviour would be that cache items are given a TTL when defined in Symfony.

Would be great to have some feedback on this. We could possibly provide a PR.

fredriktid avatar Mar 04 '21 11:03 fredriktid

Hi!

Thanks for the issue and the research!

However, Tags Bundle only reuses configuration from eZ Platform/Ibexa kernel and does not control cache pool at all. So any changes to default config should be done on eZ repos, not here.

I hope this makes sense to you?

emodric avatar Mar 04 '21 11:03 emodric

Thanks for the quick reply. Your description would be the expected behaviour but we're experiencing something else.

redis:6379[1]> TTL namespace:ez-content-info-27475
(integer) 29159
redis:6379[1]> TTL namespace:netgen-tag-2466-0-1
(integer) 29101
redis:6379[1]> TTL namespace:tag-tag-6161
(integer) -1
redis:6379[1]> TTL namespace:tag-content-14291
(integer) -1

It seems to me that eZ-keys (prefixed with ez:) all have a TTL, but some keys from this bundle don't. When I run the following command to list all keys without a TTL, only keys named tag-* are returned.

redis-cli -n 1 keys  "*" | while read LINE ; do TTL=`redis-cli -n 1 ttl "$LINE"`; if [ $TTL -eq  -1 ]; then echo "$LINE"; fi; done;

Though I haven't dived into your code enough to point out any bugs yet.

fredriktid avatar Mar 04 '21 11:03 fredriktid

It might be that eZ made some modifications to their caching layer since the last time anyone touched the cache layer here in Tags Bundle. That seems to me the most reasonable asumption.

If you have time, it would be appreciated if you can look into it. I will try to find some time too.

emodric avatar Mar 04 '21 11:03 emodric

Absolutely, I'll try to find some time in the following days.

fredriktid avatar Mar 04 '21 11:03 fredriktid