9.9.14 • Published 3 years ago

@zero-version/key-value-storage.cache v9.9.14

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
3 years ago

Key/value storage as a cache.

Usage

import { cacheKeyValueStore } from '@zero-version/key-value-storage.cache';
import { memoryKeyValueStore } from '@zero-version/key-value-storage.memory';

const store = memoryKeyValueStore(); // Can be any key/value store
const cache = cacheKeyValueStore(store, 500); // 500 ms expiry

const run = async () => {
  cache.set('my-value', { some: 'value' });

  console.log(cache.get('my-value'));
  // -> { some: 'value' } (cache hit)

  // Wait a second...
  await new Promise((resolve) => setTimeout(resolve, 1000));

  console.log(cache.get('my-value'));
  // -> undefined (cache miss)
};

run();

Support ☕

Are you using a package I've developed and finding it useful? Or have you looked at one of my repositories and learnt something new? If so, please consider buying me a coffee. Thanks!