While developing a high-loading project, I need to know the date when cache will be expired, so I could refresh its value using background jobs before the user requests it.
The framework doesn't provide information about the expiration of a cache item, so I would like to propose to create a method to implement it so, the method will return Carbon instance of expiration time.
$expiresAt = app('cache')->expiresAt('some_cache_id');
I could implement it for different cache drivers if this feature will helpful for others too.
Thanks, vt this isn't possible to easily implement everywhere. See our rate limiter class in the cache component for example. It has to implement expiry on top, because it's not possible natively.
@GrahamCampbell, the limiter class does not contains any information about the cache lifetime cause it was not intended to.
To implement the lifetime saving feature in every driver we could easily use array on top of the cache item like the Illuminate\Cache\FileStore
does. So every cache item will look like this:
$item = ['value' => $value, 'time' => $time]
Did this ever get anywhere? Or was there any similar proposal accepted?
This would be a super useful feature.
I have a need for this feature, exactly as @andrii-androshchuk stated.
Has anyone solved this elegantly? Share your pointers! I can only think of driver-specific hacks. :hammer:
@GrahamCampbell, a few more people have asked about this feature. Maybe it makes sense to provide it?
Have this ever been implemented? :-) Although, this might lead to a practice of using cache to store actual data, instead of just caching it...
Throwing my hat into the "I have a use case" ring, Although I realised miday through writing this up that I had an alternative to address my use case, so have included below incase anyone else winds up here with the same problem.
The component I am testing currently sets the cache duration dynamically based on application configuration for variable caching rates.
I can't currently test these durations are set across an array of methods that make use of the facility, and as such I cannot guarantee resources are being cached appropriately.
TTL {key}
for a Redis instancesleep
within a function until an expiration is expecteds
not ms
!Cache::put
etc. with my own MocksCache
Most helpful comment
This would be a super useful feature.