0.0.6 • Published 2 years ago
memory-kv v0.0.6
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