2.3.0 • Published 12 months ago

@aegenet/belt-memory-cache v2.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

npm version

@aegenet/belt-memory-cache

Basic memory cache with TTL

💾 Installation

yarn add @aegenet/belt-memory-cache@^2.0.0
# or
npm i @aegenet/belt-memory-cache@^2.0.0

📝 Usage

import { MemoryCache } from '@aegenet/belt-memory-cache';

const cache = new MemoryCache({
  // The interval in minutes at which the cache will be cleaned up. -> default: 5
  cleanupIntervalMinutes: 5,
  // If true, values will be cloned before being stored in the cache. -> default: true
  cloneValues: true,
  // Convert the key before storing it in the cache. -> default: (key) => key
  convertKey: (key: unknown) => key,
});
// The cache will remove all expired items every 5 minutes
cache.start();

cache.set('key', 'value', 1); // 1000ms
cache.get('key'); // 'value'

await setTimeout(1000);

cache.get('key'); // undefined

// Stop the cache cleanup
cache.stop();
2.3.0

12 months ago

2.2.0

1 year ago