multi: boostrap local cache
Kikobeats opened this issue · comments
Normally you are going to combine keyv/multi
remote strategy with a local in-memory strategy.
Right now, when the value is not on the local store but it's present on the remote store, it's copied:
https://github.com/microlinkhq/keyv/blob/master/packages/multi/src/index.js#L36
What could be cool there is to add a way to bootstrap the local strategy by copying the content from remote.
Something like:
const keyv = new Keyv({
store: new KeyvMulti({
local: new Map(),
remote: new KeyvRedis(),
bootstrap: async () => {
const keys = await this.remote.redis.keys('dns:*')
return this.remote.redis.gmet(keys)
}
})
})
Where the bootstrap code is run at the beginning to bootstrap the local storage.