Feature Request: Wrapper to include an Expiry Date/Time #167
Labels
Feature Request
Request to add a new feature
Needs: Investigation
The issues needs investigation before implementing
Is your feature request related to a problem? Please describe.
A common problem with LocalStorage is the in-ability to set an expiration date on a specified key. This can be frustrating when the value of the key doesn't really change all that often, but when it does; since the key does not expire we do not necessarily know when to try to check again.
Describe the solution you'd like
I think a possible solution is to create an internal wrapper that takes the string or model that is provided and appends it to a custom model that also includes a TTL (where TTL is in milliseconds) field.
Example:
await SetItemAsync(key, model, ttl);
if TTL is provided wrap the model in something like this:
During the Get operation evaluate the TTL to see if it is still valid, if not then return back as though it was not found.
An added nicety would be to have a method to search all expired keys and remove them.
Additional context
There are several examples on the web on how to do this with JavaScript, here is just one example:
https://digitalfortress.tech/js/localstorage-with-ttl-time-to-expiry/
The text was updated successfully, but these errors were encountered: