Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jtsang4/ttl-db
A key-value store which supports expiration time based on IndexedDB.
https://github.com/jtsang4/ttl-db
Last synced: 8 days ago
JSON representation
A key-value store which supports expiration time based on IndexedDB.
- Host: GitHub
- URL: https://github.com/jtsang4/ttl-db
- Owner: jtsang4
- License: mit
- Created: 2021-11-12T07:04:10.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-16T07:49:14.000Z (over 2 years ago)
- Last Synced: 2024-10-29T02:10:02.780Z (21 days ago)
- Language: TypeScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ttl-db
A key-value store which supports expiration time based on IndexedDB.
Powered by [idb-keyval](https://github.com/jakearchibald/idb-keyval).
## Installation
Install dependencies,
```bash
$ npm i ttl-db --save
```
## APIAll APIs return a promise because all of them is asynchronous operation.
### `set`:
Set value by key, support expiration time.
```ts
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.
```ts
import { get } from 'ttl-db';get(key);
```### `setMany`:
Set batch of key-value parallelly for speed up, support expiration time.
```ts
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.
```ts
import { getMany } from 'ttl-db';get([key1, key2]);
```### `update`:
Update value of key.
```ts
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.
```ts
import { del } from 'ttl-db';del(key);
```### `delMany`:
Delete keys.
```ts
import { delMany } from 'ttl-db';delMany([key1, key2]);
```### `clear`:
Clear entire store.
```ts
import { clear } from 'ttl-db';clear();
```