Replies: 1 comment
-
The best approach would be 2 keys. One with the data, one with the expiry date. There is not really a extra method needed for that, this is how the ratelimiter works for example. But if you really want to, I think this would be the best approach ... |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Synopsis
I'm running a large(ish) query and caching the data for a set period of time, and wanting to display to the user how long is remaining until the data is refreshed in the cache. To test this, I manually modified the
FileStore
andDatabaseStore
classes within my project'svendor/
directory to add a method that will return the expiry time as a human readable string (or optionally the UNIX timestamp).Protocols such as Memcached do not provide an efficient API to retrieve the expiry time of a cached item, unless you store the expiry time alongside the actual data being cached, but that would likely be a breaking change within the Laravel codebase if this was to happen. I have also not provided methods for other stores such as
RedisStore
orDynamoDbStore
etc. as I was quickly testing solutions before drafting this idea.I am open to seeing suggestions as to what should happen if this were to be a feature within the Cache system in Laravel. For example, as mentioned, protocols such as Memcached do not provide a way to retrieve the expiry time, so should the method exist, but return null? Or should it not exist at all?
Creating the method, but returning null, would mean you don't get an error when calling via the cache helper function:
Not having the method would of course mean you receive an error.
Proposed usage
Get the expiry time as a human readable string
Get the UNIX timestamp
View the draft PR
Beta Was this translation helpful? Give feedback.
All reactions