npm.io
0.0.6 • Published 4 years ago

memory-kv

Licence
MIT
Version
0.0.6
Deps
1
Size
15 kB
Vulns
0
Weekly
0
Stars
4

MemoryKV

An in memory key value store. Tries to emulate Redis inside node itself.

Mainly useful for development purposes.

Useage

  • Typescript
import MemoryKV from 'memory-kv'

const cache = new MemoryKV();
await cache.set('key1', 'value');

const val = await cache.get('key1');
// val == 'value'
  • Javascript
const MemoryKV = require('memory-kv');

const cache = new MemoryKV();
await cache.set('key1', 'value');

const val = await cache.get('key1');
// val == 'value'

Features

  • Setup a TTL feature
  • Set a value with a key
  • Get a value with a key
  • Delete a value with a key
  • Get list of keys provided a pattern

TTL Strategy

  • timeout holder is set to the next execution of the executor with the time it will run
  • when a new entry with a ttl is added check if that time is sooner than the timeout, if so cancel the timeout holder and set a new one

Keywords