@keyv/tiered
Tiered storage adapter for Keyv to manage local and remote store as one for Keyv
Tiered storage adapter for Keyv.
Install
npm install --save keyv @keyv/tiered
Usage
First, you need to provide your local
and remote
stores to be used, being possible to use any Keyv storage adapter:
import Keyv from 'keyv';
import KeyvTiered from '@keyv/tiered';
import KeyvSqlite from '@keyv/sqlite';
const remoteStore = () => new Keyv({
store: new KeyvSqlite({
uri: 'sqlite://test/testdb.sqlite',
busyTimeout: 30_000,
}),
});
const localStore = () => new Keyv();
const remote = remoteStore();
const local = localStore();
const store = new KeyvTiered({remote, local});
const keyv = new Keyv({store});
keyv.on('error', handleConnectionError);
API
KeyvTiered([options])
options
local
Type: Object
new Keyv()
A keyv instance to be used as local strategy.
remote
Type: Object
new Keyv()
A keyv instance to be used as remote strategy.
validator
Type: Function
() => true
The validator function is used as a precondition to determining is remote storage should be checked.