file-cache
File-based cache for JSON-serializable data.
Install
Requires at least Node.js v14.14.0.
npm install @uwdata/file-cache
Usage
@uwdata/file-cache
is an ESM-only module - you are not able to import it with require()
.
Standard Usage
import { fileCache } from '@uwdata/file-cache';
const cache = fileCache();
await cache.set('key', { value: true });
const value = await cache.get('key');
await cache.delete('key');
await deleteCache();
Custom Usage
import { fileCache, deleteCache } from '@uwdata/file-cache';
const cache = fileCache({
cacheDir: './.my-cache-dir',
defaultTTL: 60 * 1000,
});
await cache.set('key', { value: true }, 120 * 1000);
await deleteCache('./.my-cache-dir');