ttl-db
v0.9.2
Published
A key-value store which supports expiration time based on IndexedDB.
Downloads
5
Readme
ttl-db
A key-value store which supports expiration time based on IndexedDB.
Powered by idb-keyval.
Installation
Install dependencies,
$ npm i ttl-db --save
API
All APIs return a promise because all of them is asynchronous operation.
set
:
Set value by key, support expiration time.
import { set } from 'ttl-db';
set(key, value); // won't expire
// or
set(key, value, { ttl: 60 }); // expires after 60 seconds
get
:
Get value by key.
import { get } from 'ttl-db';
get(key);
setMany
:
Set batch of key-value parallelly for speed up, support expiration time.
import { setMany } from 'ttl-db';
setMany([
[key1, value1], // won't expire
[key2, value2, { ttl: 60 }], // expires after 60 seconds
]);
getMany
:
Get batch of value parallelly for speed up.
import { getMany } from 'ttl-db';
get([key1, key2]);
update
:
Update value of key.
import { update } from 'ttl-db';
update(key, (oldValue) => oldValue + 1); // won't expire
// or
update(key, (oldValue) => oldValue + 1, { ttl: 60 }); // expires after 60 seconds
del
:
Delete key.
import { del } from 'ttl-db';
del(key);
delMany
:
Delete keys.
import { delMany } from 'ttl-db';
delMany([key1, key2]);
clear
:
Clear entire store.
import { clear } from 'ttl-db';
clear();