Registry / storage / expire-cache

expire-cache

JSON →
library1.0.0jsnpmunverified

A simple JavaScript cache library that supports key-value storage with configurable expiration times and namespacing. Version 1.0.0 (stable, last updated 2017) is available via npm and Bower. It offers a concise API with function overloads for get/set/remove and namespace support, allowing hierarchical sub-caches with independent expiry. The library is lightweight and works in Node.js and browsers via script tag or AMD.

npm install expire-cache
INSTALL
IMPORT
SIG · EXPIRE-CACHE
E
expire-cache
storagejavascriptv1.0.0
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.

expireCache
const expireCache = require('expire-cache');
import expireCache from 'expire-cache';
The package does not ship ESM; use CommonJS require(). If using bundlers that support ESM, a default import may fail.
expireCache
const expireCache = require('expire-cache');
const { expireCache } = require('expire-cache');
The module exports a single function, not an object with named exports.
expireCache (browser script)
<script src="/pathTo/expire-cache/index.js"></script>
const expireCache = require('expire-cache'); inside browser without bundler
For browser use, include via script tag; the library expects window.expireCache.

Demonstrates basic set/get with default and custom expiry, namespace usage, and removal.

const expireCache = require('expire-cache'); // Set with default 5s expiry expireCache('key1', 123); console.log(expireCache('key1')); // 123 // Set with custom 10s expiry expireCache.set('key2', 456, 10); console.log(expireCache.get('key2')); // 456 // Create namespace with 1s expiry const cache1 = expireCache.namespace('test', 1); cache1('key', 789); console.log(cache1('key')); // 789 // Remove key expireCache.remove('key1'); console.log(expireCache('key1')); // undefined
Debug
Known issues
gotchaThe expireCache() function can be called with no arguments to retrieve all data, but also as a getter with a key. Be careful not to confuse the two patterns.
fix
Use .get() and .set() for clarity.
affects: >=0.0.0
deprecatedThe package has not been updated since v1.0.0 (2017). It lacks modern features like ESM, TypeScript types, and promises.
fix
Consider alternatives like lru-cache or node-cache.
affects: >=1.0.0
gotcharemove() can accept multiple keys as separate arguments or as an array, but mixing both (e.g., .remove('key', ['key1','key2'])) may not work as expected in older versions.
fix
Use an array for multiple keys: .remove(['key1', 'key2']).
affects: >=0.0.0
gotchaThe default expire time is 5 seconds. If you set a value without expire, it may be removed after 5 seconds.
fix
Explicitly set a large expire value if you want persistent cache.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: expireCache is not a function
The package is not imported correctly or the script is not loaded.
fix
Ensure require('expire-cache') returns a function. In browser, check script src.
expireCache(...) is not a function after import
Using ES6 import on a CommonJS module.
fix
Use const expireCache = require('expire-cache') instead of import.
require is not defined
Running in a browser without a module bundler.
fix
Use the script tag method: <script src="node_modules/expire-cache/index.js"></script>
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
expire-cache — npm install expire-cache · libregistry