@zero-version/key-value-storage.cache
TypeScript icon, indicating that this package has built-in type declarations

9.9.14 • Public • Published

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!

Package Sidebar

Install

npm i @zero-version/key-value-storage.cache

Weekly Downloads

1

Version

9.9.14

License

UNLICENSED

Unpacked Size

2.9 kB

Total Files

5

Last publish

Collaborators

  • andrewcrobertson