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

Optionally use sessionStorage #34

Open
aaronshaf opened this issue Sep 10, 2014 · 3 comments
Open

Optionally use sessionStorage #34

aaronshaf opened this issue Sep 10, 2014 · 3 comments

Comments

@aaronshaf
Copy link

No description provided.

@tgroshon
Copy link

Just submitted a pull-request that "should" do this :)
#36

@bcowgill
Copy link

bcowgill commented Mar 6, 2015

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

@JoniJnm
Copy link

JoniJnm commented Oct 29, 2015

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

    //...
}));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants