Registry / storage / ttl-flat-cache-fixed

ttl-flat-cache-fixed

JSON →
library1.0.1jsnpmunverified

A lightweight, file-based caching library with Time-To-Live (TTL) support, built on top of flat-cache. Current version 1.0.1 provides convenient methods set(), get(), and del() that automatically handle expiration, while still exposing the underlying flat-cache API. It defaults to no expiry unless explicitly configured. Key differentiator is the simplicity of adding TTL to flat-cache without additional dependencies. The package ships TypeScript types.

npm install ttl-flat-cache-fixed
INSTALL
IMPORT
SIG · TTL-FLAT-CACHE-FIX
T
ttl-flat-cache-fixed
storagejavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (ttl-flat-cache-fixed)
import cache from 'ttl-flat-cache-fixed';
const cache = require('ttl-flat-cache-fixed');
The package is ESM-only. CommonJS require will fail.
cache.set(key, value, ttl?)
cache.set('myKey', { data: 123 }, 60);
cache.setKey('myKey', { data: 123 }, 60);
set() is the TTL-aware method. flat-cache's setKey() is still available but does not handle TTL.
cache.get(key)
cache.get('myKey');
cache.getKey('myKey');
TTL-aware get() returns undefined if expired. Use getKey() to bypass TTL check.

Demonstrates initialization with options object, set/get with TTL, and checking remaining time using ttl() method.

import cache from 'ttl-flat-cache-fixed'; const opts = { ns: 'my-cache', ttl: 3600 * 24 // 24 hours default TTL }; const myCache = cache(opts); myCache.set('user', { name: 'Alice' }, 60); // expires in 60 seconds console.log(myCache.get('user')); // { name: 'Alice' } console.log(myCache.ttl('user')); // e.g., { key: 'user', expires: 'in a few seconds' } // After TTL setTimeout(() => { console.log(myCache.get('user')); // undefined }, 60000);
Debug
Known issues
gotchaThe package extends flat-cache; calling setKey() directly does not apply TTL. Always use set() for TTL-aware caching.
fix
Use cache.set(key, value, ttl) instead of cache.setKey(key, value).
affects: >=1.0.0
deprecatedPackage name 'ttl-flat-cache-fixed' may be confused with the original 'flat-cache' — ensure correct import.
fix
Install and import from 'ttl-flat-cache-fixed', not 'flat-cache'.
affects: >=1.0.0
gotchaThe ttl option in constructor sets a default TTL, but each set() call can override it. If no ttl provided to set(), the default from options is used.
fix
Check that you pass ttl to set() if you want a specific expiration; otherwise rely on the default.
affects: >=1.0.0
gotchaCache data is stored as JSON files on disk. Deleting the cache directory manually will cause errors.
fix
Use cache.destroy() to clean up cache files instead of manual deletion.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'ttl-flat-cache-fixed'
Package not installed or use in CommonJS project without ESM import.
fix
Run 'npm install ttl-flat-cache-fixed' and ensure your project uses ESM (type: module in package.json) or use dynamic import: const cache = await import('ttl-flat-cache-fixed');
TypeError: cache.set is not a function
Importing the default export incorrectly, e.g., using named import.
fix
Use default import: import cache from 'ttl-flat-cache-fixed'; then invoke cache(opts).
TypeError: cache.getKey is not a function
The package does not re-export flat-cache's getKey as a direct method; it's available only via the underlying cache instance returned from the factory.
fix
Access flat-cache methods through the cache instance returned from cache(opts), e.g., const myCache = cache(opts); myCache.getKey(key);
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
flat-cacherequiredCore caching logic; ttl-flat-cache-fixed extends its functionality with TTL.
Agent activity
27 hits · last 30 days
node
24
OpenAI (training)
1
Resources