A simple key/value cache that persists data to files, backed by an in-memory cache (CacheableMemory). Version 6.1.22 is the current stable release. Part of the Cacheable ecosystem, it combines in-memory speed with file persistence, supporting TTL, LRU eviction, expiration intervals, and automatic save intervals. Replaces the v5 prune method with built-in eviction from CacheableMemory. Ships ESM and CommonJS with TypeScript typings. Notable changes in v6: removed global functions (use imports), replaced prune with ttl/lruSize, changed save() behavior (no longer needs prune option), and introduced new options like serialize/deserialize.
npm install flat-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a FlatCache with TTL, LRU, expiration check, and persistence at intervals. Sets, gets, and removes a value.
Replace global calls with imported ones: e.g., use `import { createFromFile } from 'flat-cache'` instead of global `createFromFile`.Remove calls to cache.prune(). Configure eviction via options `ttl`, `lruSize` in FlatCache constructor.
Remove prune boolean from save() calls. Use constructor options for eviction.
Use `createFromFile(path)` to load an existing cache from disk.
Either stick with default flatted serialization or ensure custom serializer/deserializer are consistent across create and load.
Install the package: npm install flat-cache. Ensure your tsconfig.json includes 'node' moduleResolution or use 'bundler' for ESM.
Use `import { createFromFile } from 'flat-cache'` and call `createFromFile('./cacheDir')`.Remove any calls to `cache.prune()`. Set ttl and lruSize in constructor options.
Use a simple identifier (e.g., 'myCache') and specify the directory separately via `cacheDir` option.