Registry / storage / nice-cache

nice-cache

JSON →
library0.0.5jsnpmunverified

An in-memory cache for Node.js with auto-refresh and auto-flush mechanisms. Version 0.0.5 (last release, no recent updates). It allows setting, getting, and subscribing to a refresh loop. Differentiates from simple caches by providing a subscription model for asynchronous refresh of expired keys. Requires Node 0.8.0. No longer actively maintained.

npm install nice-cache
INSTALL
IMPORT
SIG · NICE-CACHE
N
nice-cache
storagejavascriptv0.0.5
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.

Cache
const Cache = require('nice-cache');
import Cache from 'nice-cache';
The package does not provide ESM exports; use CommonJS require.
Cache (named)
const { Cache } = require('nice-cache');
const Cache = require('nice-cache').Cache;
Default export is the Cache constructor; named export does not exist.
new Cache(options)
const cache = new Cache({ refreshInterval: 60 });
const cache = new Cache({ refreshInterval: 60, singleton: false }); // default is true
Options object is optional; defaults are documented.

Demonstrates creating a nice-cache instance with refresh interval, setting and getting cached values, and subscribing a refresh function for background updates.

const Cache = require('nice-cache'); const http = require('http'); const cache = new Cache({ refreshInterval: 60 }); const getUsers = (callback) => { // simulate async fetch setTimeout(() => callback(null, 'user data'), 100); }; http.createServer((req, res) => { let users = cache.get('api-responses', 'users'); if (users) { return res.end(users); } getUsers((err, result) => { cache.set('api-responses', 'users', result); cache.sub('api-responses', 'users', getUsers); res.end(result); }); }).listen(1337, '127.0.0.1'); console.log('Server running at http://127.0.0.1:1337/');
Debug
Known issues
deprecatedPackage is no longer maintained; last version published 2014. No security updates or Node version compatibility beyond 0.8.
fix
Consider using a modern caching library like lru-cache or node-cache.
affects: 0.0.5
breakingRequires Node 0.8 or higher; may not work on modern Node versions (v12+).
fix
Use a Node 12+ compatible cache library.
affects: >=0.0.0
gotchaSingleton option defaults to true; successive new Cache() returns same instance unless singleton:false.
fix
Explicitly pass { singleton: false } to create separate instances.
affects: >=0.0.0
gotchaCache#refresh() only works after Cache#sub() has been called; calling refresh on unsubscribed key has no effect.
fix
Ensure sub() is called before refresh() for a given key/type.
affects: >=0.0.0
Errors
Common errors & fixes
cache.get is not a function
Importing package incorrectly (e.g., using default import as object).
fix
Use const Cache = require('nice-cache'); const cache = new Cache();
undefined is not a function
Calling .sub or .refresh on undefined because cache instance not created properly.
fix
Ensure new Cache() is called and assigned to a variable.
Upgrade
Version history
0.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources
nice-cache — npm install nice-cache · libregistry