vue-ls
vue-ls copied to clipboard
Suggestion: Add ability to cleanup expired values
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.
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
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
})
Ok, that's a good idea.
You can do it like this:
Well, this requires the knowledge of keys format. Shouldn't it be encapsulated in vue-ls?
@RobinCk any news with the keys
option ?
you can do pull request, if so necessary
np, but i dont know how π