marcuswestin / store.js

Cross-browser storage for all use cases, used across the web.
MIT License
14.01k stars 1.33k forks source link

How to establish expiration time using the js file #263

Closed jonalxh closed 6 years ago

jonalxh commented 6 years ago

Hi, I wanna know how to set an expiration time using the store.everything.min.js file, I'm working in a Non Node based application.

I'm trying to define my vars like this, with non success result:

store.set('settings', 'settings', 3000);
store.set('settings', 'settings'[,3000]);
store.set('settings', 'settings'[3000]);

The expected result is to clear the Local Storage var after 3 secs (i think time is defined in ms). After this time im getting the var and it shows me the value, what means it's never being cleared.

Could you explain me how to do it please?

jonalxh commented 6 years ago

Ok, I'm goin to answer mi own question:

First I had to create a variable called expiration, which contains an object with the current date and in the same var im adding the time that I want it keep alive, in my case 10 seconds (10000 miliseconds)

var expiration = new Date().getTime() + 10000;

Then I had to add the variable value to my set:

store.set('bar', 'foo', expiration);

And thats it.