-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Description
Symfony version(s) affected: 5.1.7 (not tested on other version)
Description
I will only talk about TTL in this issue because it's more easy to show problem, but it can be with all properties who can be set in ItemInterface. I work with CacheContracts
When we set manually TTL for an item (like in documentation), only the last adapter configured is correctly set with the good TTL
How to reproduce
Cache config with default TTL to 2000
cache:
default_redis_provider: redis://%env(REDIS_HOST)%:%env(int:REDIS_PORT)%
pools:
chain_cache:
default_lifetime: 2000
adapters:
- cache.adapter.apcu
- cache.adapter.redis
Demo controller to add value in cache with a TTL value to 5000
/**
* @Route("/", methods={"GET"})
*/
public function index(CacheInterface $chainCache) {
$chainCache->get('chain', function (ItemInterface $item) {
$item->expiresAfter(5000);
return 'chain';
});
}
And to see problem we need to add breakpoint, see Additional context for example
Possible Solution
Don't know for the moment
But callback function (defined in my controller) are executed only for the last adapter because the callback are replaced to chain other adapters configured
Additional context
The value set in controller not to be cached, clear cache if you're not sure
Add breakpoint here and add variable in debugger $metadata['expiry']-time()
to see ttl
I screen result below in order :
- First 'loop' it's
RedisAdapter
called with a TTL to 5000 (redis is the last adapter configured in my config)
- Next (and last beacause I have configured only 2 adapters), it's
ApcuAdapter
with a TTL to 2000 (default value) and not 5000
I also check in redis (with redis-cli + redis library php) and apcu (with apcu_cache_info) and values are set like in my screenshot
I hope you understand problem, else I can try to explain again, or in french it's will be easy for me...
Thanks