Open waghcwb opened 4 years ago
if anyone need a workaround, this should work
const Constants = {
storage: {
mykey: 'myvalue',
}
}
const now = new Date();
const inFiveDays = new Date(now.setDate(now.getDate() + 5));
let mykey
if (!(mykey = storage.get(Constants.storage.mykey))) {
mykey = fnToGetMyKeys();
storage.set(Constants.storage.mykey, {
list: mykey,
maxAge: inFiveDays,
});
} else {
const expiration = new Date(storage.get(Constants.storage.mykey).maxAge);
const invalidateKeys = [Constants.storage.mykey];
if (expiration < new Date()) {
for (const key of invalidateKeys) {
storage.delete(key);
}
}
}
I don't see the use-case for setting a expiration date for the whole store, but I agree it could be useful on a per-key basis.
This will need to be implemented in https://github.com/sindresorhus/conf first and then just copy-paste the new readme docs over here.
We already have a mechanism in place to store internal metadata, which could be used to store the expirations for keys: https://github.com/sindresorhus/conf/blob/410cc144141f1467cc91fe4b16f6b7f42a8afac8/index.js#L39
Is still being considered? I'm writing a useragent spoofer and caching it with electron-store.
It'd be super neat to be able to set an expiry time for it!
It would be awesome if we can set a max age for a single key or the whole store.
For example: