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

Suggestion: Add ability to cleanup expired values #29

Open
Hankus opened this issue Apr 16, 2018 · 7 comments
Open

Suggestion: Add ability to cleanup expired values #29

Hankus opened this issue Apr 16, 2018 · 7 comments

Comments

@Hankus
Copy link

Hankus commented Apr 16, 2018

Having the ability to set expiry on values is great, but there is no cleanup methods apart from clear() which removes all local data.

Suggest there could be a cleanupExpired() function which would prune out all the expired data values.

@RobinCK
Copy link
Owner

RobinCK commented Apr 19, 2018

I do not see the point
You can do it like this:

for (const key of Object.keys(localStorage)) {
    const vueStorageName = key.replace('your_namespace', '');
    if (Vue.ls.get(vueStorageName, undefined) === undefined) {
        Vue.ls.remove(vueStorageName);
    }
}

code not tested

@ctf0
Copy link

ctf0 commented Apr 23, 2018

maybe we can have a keys method so something like

let now = Date.now() // timestamp

this.$ls.keys(localStorage).map((key) => {
    return this.$ls.get(key).expire < now 
        ? this.$ls.remove(key) 
        : false
})

@RobinCK
Copy link
Owner

RobinCK commented Apr 23, 2018

Ok, that's a good idea.

@feugenix
Copy link

You can do it like this:

Well, this requires the knowledge of keys format. Shouldn't it be encapsulated in vue-ls?

@ctf0
Copy link

ctf0 commented May 31, 2020

@RobinCK any news with the keys option ?

@RobinCK
Copy link
Owner

RobinCK commented May 31, 2020

you can do pull request, if so necessary

@ctf0
Copy link

ctf0 commented May 31, 2020

np, but i dont know how 😞

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