2.0.2 • Published 9 months ago
@keyv/tiered v2.0.2
@keyv/tiered
Tiered storage adapter for Keyv to manage local and remote store as one for Keyv
Feature is Deprecated
This feature is deprecated and will be removed in 2025 as it is no longer needed.
offline
and tiered
mode for caching is built into the core Cacheable library which uses Keyv under the hood. Please use the Cacheable
library for offline
and tiered
caching.
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
Default: new Keyv()
A keyv instance to be used as local strategy.
remote
Type: Object
Default: new Keyv()
A keyv instance to be used as remote strategy.
validator
Type: Function
Default: () => true
The validator function is used as a precondition to determining is remote storage should be checked.