lscache icon indicating copy to clipboard operation
lscache copied to clipboard

Optionally use sessionStorage

Open aaronshaf opened this issue 10 years ago • 3 comments

aaronshaf avatar Sep 10 '14 18:09 aaronshaf

Just submitted a pull-request that "should" do this :) https://github.com/pamelafox/lscache/pull/36

tgroshon avatar Sep 16 '14 15:09 tgroshon

Don't see this in the main code. was hoping this lib did sessionStorage too.

bcowgill avatar Mar 06 '15 14:03 bcowgill

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

    //...
}));

JoniJnm avatar Oct 29 '15 11:10 JoniJnm