lscache
lscache copied to clipboard
Optionally use sessionStorage
Just submitted a pull-request that "should" do this :) https://github.com/pamelafox/lscache/pull/36
Don't see this in the main code. was hoping this lib did sessionStorage too.
I don't know if it should be an extra param like "time" or "ttl".
lscache.set('mykey1', 'myvalue1', 10); //mykey1 is dirty and can be deleted in 10 minutes
lscache.set('mykey2', 'myvalue2', 0, true); //mykey2 is dirty and can be deleted when user closes the browser
lscache.set('mykey3', 'myvalue3', 10, true); //mykey3 is dirty and can be deleted when user closes the browser or in 10 minutes
Or/and lscache factory should have both storages like window
lscache.local.set('mykey4', 'myvalue4', 10);
lscache.session.set('mykey5', 'myvalue5', 10);
(function (root, factory) {
//...
}(this, function () {
var Cache = function(driver) {
this.driver = driver;
};
Cache.prototype = {
isSupported: function() {
if (this.driver === undefined) return false;
//test set
},
set: function(name, value, ttl) {
//...
this.driver.setItem(name, value);
//...
}
get: function(name){},
del: function(){}
};
var lscache = {
//legacy mode?
set: function(name, value, ttl, session) {
if (session) this.session.set(name, value, ttl);
else this.local.set(name, value, ttl);
}
};
lscache.session = new Cache(this.sessionStorage); //window.sessionStorage
lscache.local = new Cache(this.localStorage); //window.localStorage
//...
}));