Registry / storage / cache-list

cache-list

JSON →
library0.1.9jsnpmunverified

A simple caching library for Node.js with both in-memory (MemoryCache) and Redis (RedisCache) backends. Version 0.1.9 supports features like default TTL, key prefixing, serialization toggle, atomic add, multi-get/set, and flush. It ships TypeScript types and provides a clean API similar to Yii2 caching. Release cadence is low; the package appears stable but not actively maintained. Compared to node-cache or node-cache-manager, it offers a unified interface for memory and Redis with minimal configuration.

npm install cache-list
INSTALL
IMPORT
SIG · CACHE-LIST
C
cache-list
storagejavascriptv0.1.9
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.

MemoryCache
import { MemoryCache } from 'cache-list'
const MemoryCache = require('cache-list').MemoryCache
ESM default; Node >=14.15.0 required.
RedisCache
import { RedisCache } from 'cache-list'
import RedisCache from 'cache-list'
RedisCache is a named export, not default.
MemoryCache (type)
import type { MemoryCache } from 'cache-list'
TypeScript users can import types separately.

Initializes MemoryCache, demonstrates set/get with TTL, exists, delete, multi operations, atomic add, and flush.

import { MemoryCache } from 'cache-list'; const cache = new MemoryCache({ defaultDuration: 600, // 10 minutes }); // Basic operations cache.set('greeting', 'Hello'); console.log(cache.get('greeting')); // 'Hello' // With custom TTL (seconds) cache.set('key2', { data: 'value' }, 3600); // Check existence if (cache.exists('key2')) { console.log('Key exists'); } // Delete single key cache.delete('key2'); // Multi operations cache.multiSet([{ key: 'a', value: 1 }, { key: 'b', value: 2 }]); const results = cache.multiGet(['a', 'b']); console.log(results); // { a: 1, b: 2 } // Atomic add (only if key does not exist) cache.add('unique', 'first'); cache.add('unique', 'second'); // fails silently console.log(cache.get('unique')); // 'first' // Flush all cache.flush();
Debug
Known issues
gotchaget() returns false for missing/expired keys, not null or undefined. Use strict inequality to check existence (value !== false) rather than if(value).
fix
Replace if (cache.get('key')) with if (cache.get('key') !== false) or use cache.exists() first.
affects: >=0.0.0
breakingMD5 hashing is used when key is not a simple alphanumeric string <=32 chars. This may cause collisions if keys are arbitrary objects or long strings.
fix
Ensure keys are short alphanumeric strings to avoid hashing, or be aware of collision risk.
affects: >=0.0.0
deprecatedThe default export is not defined; importing from the package root works only as named exports since v0.1.0.
fix
Use named imports: import { MemoryCache } from 'cache-list'.
affects: >=0.1.0
gotchamultiGet returns an object with keys as strings, but the returned values may be false for missing keys. Do not use for...in without checking hasOwnProperty.
fix
Iterate with for (const key of Object.keys(results)) if needed, and check results[key] !== false.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'redis'
Trying to use RedisCache without installing the optional dependency 'redis'.
fix
Run 'npm install redis' and ensure it is installed alongside cache-list.
get() always returns false even though key was set
TTL may have expired, or the key was set with defaultDuration=0 (infinite) but the cache was flushed or overwritten.
fix
Check TTL configuration, use cache.exists() before get(), and verify no flush or delete occurred.
TypeError: cache.set is not a function
Importing the package incorrectly (e.g., default import instead of named import).
fix
Use correct named import: import { MemoryCache } from 'cache-list'; then instantiate with new.
Upgrade
Version history
0.1.9latest on npm
Audit
Dependencies
redisoptionalRequired when using RedisCache; optional if only MemoryCache is used.
Agent activity
31 hits · last 30 days
node
30
Resources
cache-list — npm install cache-list · libregistry