Registry / storage / nano-cache

nano-cache

JSON →
library1.1.2jsnpmunverified

nano-cache is a lightweight in-memory cache for Node.js (version 1.1.2, last updated 2018). It provides TTL, access-limit, and memory-limit based expiration with LRU eviction, compressed storage for higher capacity, and event emitters for cache operations. Unlike larger caches like node-cache or lru-cache, it focuses on simplicity and supports per-item TTL/limit overrides. It requires JSON-serializable values and emits events on get/set/del/clear. No breaking changes have been reported, but the package is in maintenance mode.

npm install nano-cache
INSTALL
IMPORT
SIG · NANO-CACHE
N
nano-cache
storagejavascriptv1.1.2
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 singleton
const cache = require('nano-cache');
import cache from 'nano-cache';
Package uses CommonJS and exports a singleton by default. No ESM export available.
NanoCache constructor
const NanoCache = require('nano-cache'); const cache = new NanoCache();
const { NanoCache } = require('nano-cache');
The constructor is the default export; destructuring results in undefined.
NanoCache.SIZE constants
const NanoCache = require('nano-cache'); const bytes = 100 * NanoCache.SIZE.MB;
const { SIZE } = require('nano-cache');
SIZE is a static property on the constructor, not a separate export.

Creates a cache with a 60-second TTL and 10 MB memory limit, sets a key, retrieves it, and logs stats.

const NanoCache = require('nano-cache'); const cache = new NanoCache({ ttl: 60000, bytes: 10 * NanoCache.SIZE.MB }); cache.on('set', (key) => console.log(`Set: ${key}`)); cache.set('user', { id: 1, name: 'Alice' }); const user = cache.get('user'); console.log(user); // { id: 1, name: 'Alice' } console.log('Stats:', cache.stats());
Debug
Known issues
gotchaValues must be JSON-serializable; objects with functions, undefined, or circular references will break.
fix
Ensure values are plain objects, strings, numbers, booleans, null, or arrays thereof.
affects: all
gotchaThe default singleton is easily shared across modules; accidental cross-contamination can occur.
fix
Use `new NanoCache()` for isolated cache instances instead of the singleton.
affects: all
gotchaEvent listeners must be removed manually to avoid memory leaks; package does not auto-clean.
fix
Call `cache.removeAllListeners()` or use scoped listeners with `cache.off()`.
affects: all
deprecatedPackage is in maintenance mode; no updates since 2018.
fix
Consider migrating to actively maintained alternatives like lru-cache or node-cache.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: cache.get is not a function
Using the singleton incorrectly (e.g., calling `NanoCache.get()` but importing wrong).
fix
Use `const cache = require('nano-cache'); cache.get('key');`
RangeError: bytes exceeds maximum allowed
Setting `bytes` option to a value larger than available memory.
fix
Reduce the `bytes` value or use `NanoCache.SIZE.MB` to stay within limits.
ReferenceError: NanoCache is not defined
Attempting to use `NanoCache.SIZE` without requiring the module.
fix
Add `const NanoCache = require('nano-cache');` at the top of the file.
Upgrade
Version history
1.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
29 hits · last 30 days
node
26
Amazon
1
OpenAI (training)
1
Resources
nano-cache — npm install nano-cache · libregistry