Registry / storage / easy-cache

easy-cache

JSON →
library0.2.0jsnpmunverified

Simple in-memory key/value cache for Node.js. Version 0.2.0 is the latest stable release. Provides basic set, get, unset, exists, size, and clear operations with optional time-to-live in milliseconds. Less feature-rich than alternatives like node-cache, but minimal and dependency-free. Suitable for small-scale caching needs.

npm install easy-cache
INSTALL
IMPORT
SIG · EASY-CACHE
E
easy-cache
storagejavascriptv0.2.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.

default
const cache = require('easy-cache');
import cache from 'easy-cache';
The package is CommonJS-only and does not support ESM import syntax.
set
cache.set('key', 'value', 100);
cache.set('key', 'value', '100');
Duration must be a number in milliseconds, not a string.
get
const val = cache.get('key');
const val = cache.get('key', true);
get() only accepts key; no extra parameters.

Demonstrates basic set, get with TTL, and clear operations.

const cache = require('easy-cache'); cache.set('greeting', 'Hello World'); console.log(cache.get('greeting')); // 'Hello World' cache.set('temp', 'expires', 100); // expires in 100ms setTimeout(() => { console.log(cache.get('temp')); // null }, 150); cache.clear(); console.log(cache.size()); // 0
Debug
Known issues
deprecatedeasy-cache is no longer actively maintained; prefer node-cache or other alternatives.
fix
Use node-cache (npm install node-cache) or a similar maintained package.
affects: >=0.0.0
gotchaDuration (TTL) is in milliseconds, not seconds. Common mistake to pass seconds.
fix
Convert seconds to milliseconds: duration * 1000.
affects: >=0.0.0
gotchaget() returns null for missing keys, but also returns null if the value is explicitly set to null? Undefined behavior.
fix
Use exists() to check existence before get() if distinction matters.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: cache.set is not a function
Incorrect import: using `import cache from 'easy-cache'` in ESM environment.
fix
Use `const cache = require('easy-cache');`
ReferenceError: cache is not defined
Module require path misspelled or not installed.
fix
Run `npm install easy-cache` and ensure require path is correct.
TypeError: Cannot read property 'foo' of null
Expecting get() to return an object but key does not exist or expired.
fix
Check key existence with exists() before accessing properties.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
32 hits · last 30 days
node
30
OpenAI (training)
1
Resources
easy-cache — npm install easy-cache · libregistry