🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

ttl-db

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ttl-db

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

latest
Source
npmnpm
Version
0.9.2
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 16 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts