Closed Awilum closed 3 years ago
Hello,
I don't understand what you're trying to do ? Are you working with the PSR6 interface or the PSR16 one ?
Anyway you can set the cache expiration of your cache item by setting it using expireAt(\Datetime)
or expireAfter(\DateInterval|int) or
I don't want to write this every time (when I am using Psr16 adapter)
->set('blog', $blogCollection, ($cacheTime + rand(0, $delta)));
->set('catalog', $catalogCollection, ($cacheTime + rand(0, $delta)));
->set('testimonials', $testimonialsCollection, ($cacheTime + rand(0, $delta)));
I want to write this
->set('blog', $blogCollection, $cacheTime);
->set('catalog', $catalogCollection, $cacheTime);
->set('testimonials', $testimonialsCollection, $cacheTime);
but delta time should be optional and comes underthehood of set
method like this
function set($key, $data, $time)
{
$delta = 60;
...->set($key, $data, ($time + rand(0, $delta)));
}
Oh I understand, in that case it's up to your own implementation.
Or you can try to alter the date with an event.
Using the onCacheSaveItem
event would allow you to add your "delta".
Thanks for your answer
Hello!
I want to use such approach with time delta for all cache set execution in my project
I want to avoid cache invalidation at once with help of time delta.
Is it possible somehow to override the
set
method for all cache drivers to add this optional feature right in theset
method?Or it's only one way, to create my class, that will add this custom logic for default
set
method?