vue-ls icon indicating copy to clipboard operation
vue-ls copied to clipboard

Suggestion: Add ability to cleanup expired values

Open Hankus opened this issue 6 years ago β€’ 7 comments

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.

Hankus avatar Apr 16 '18 21:04 Hankus

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

RobinCK avatar Apr 19 '18 13:04 RobinCK

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
})

ctf0 avatar Apr 23 '18 06:04 ctf0

Ok, that's a good idea.

RobinCK avatar Apr 23 '18 06:04 RobinCK

You can do it like this:

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

feugenix avatar Jul 14 '18 10:07 feugenix

@RobinCk any news with the keys option ?

ctf0 avatar May 31 '20 15:05 ctf0

you can do pull request, if so necessary

RobinCK avatar May 31 '20 15:05 RobinCK

np, but i dont know how 😞

ctf0 avatar May 31 '20 16:05 ctf0