# ttl-db

> A key-value store which supports expiration time based on IndexedDB.

Latest version **0.9.2** (published 2022-03-16) · 0 weekly downloads

## Install

```sh
npm install ttl-db
pnpm add ttl-db
yarn add ttl-db
bun add ttl-db
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.2 |
| Published | 2022-03-16 |
| First published | 2021-11-12 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 17.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | wtzeng |

## Links

- npm: https://www.npmjs.com/package/ttl-db
- Repository: https://github.com/jtsang4/ttl-db
- Homepage: https://github.com/jtsang4/ttl-db#readme
- Issues: https://github.com/jtsang4/ttl-db/issues
- npm.io page: https://npm.io/package/ttl-db

## Dependencies (1)

- [idb-keyval](https://npm.io/package/idb-keyval.md) ^6.0.3

## Recent versions

- 0.9.2 (latest) — 2022-03-16
- 0.9.1 — 2021-11-12
- 0.9.0 — 2021-11-12

## 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
```
## API

All 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();
```

---
_Source: https://npm.io/package/ttl-db · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
