Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Wrapper to include an Expiry Date/Time #167

Open
b1tzer0 opened this issue Dec 8, 2021 · 1 comment
Open

Feature Request: Wrapper to include an Expiry Date/Time #167

b1tzer0 opened this issue Dec 8, 2021 · 1 comment
Labels
Feature Request Request to add a new feature Needs: Investigation The issues needs investigation before implementing

Comments

@b1tzer0
Copy link

b1tzer0 commented Dec 8, 2021

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:

class ExpiryModel<T>{
  int Ttl;
  T Data;
}

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/

@b1tzer0 b1tzer0 added Feature Request Request to add a new feature Triage Issue needs to be triaged labels Dec 8, 2021
@chrissainty
Copy link
Member

Hi @b1tzer0, thanks for making this suggestion. I'm open to this as long as we implement it in a way that makes it optional and non-breaking to the existing APIs. An additional overload to a few methods could be a nice solution. It would then be on developers to know if they are expecting the wrapper object back from local storage or not.

@chrissainty chrissainty added Needs: Investigation The issues needs investigation before implementing and removed Triage Issue needs to be triaged labels Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Request to add a new feature Needs: Investigation The issues needs investigation before implementing
Projects
None yet
Development

No branches or pull requests

2 participants