Registry / storage / cache-service-cache-module

cache-service-cache-module

JSON →
library2.0.1jsnpmunverified

A lightweight cache plugin for superagent-cache and cache-service, and a standalone in-memory cache optionally backed by localStorage or sessionStorage. Version 2.0.1 is the latest stable release with no release cadence noted. It provides background refresh, per-key expiration, robust API, and compatibility with cache-service and superagent-cache. Compared to alternatives, it integrates tightly with the cache-service ecosystem and supports browser storage without external dependencies.

npm install cache-service-cache-module
INSTALL
IMPORT
SIG · CACHE-SERVICE-CACH
C
cache-service-cache-module
storagejavascriptv2.0.1
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.

CacheModule
✓ const CacheModule = require('cache-service-cache-module');
✗ import CacheModule from 'cache-service-cache-module';
This package uses CommonJS; ESM import may fail or require default interop.
CacheModule with config
✓ const CacheModule = require('cache-service-cache-module'); const cache = new CacheModule({storage: 'session', defaultExpiration: 60});
✗ const CacheModule = require('cache-service-cache-module').default;
No .default export; require returns the constructor directly.
.set()
✓ cache.set('key', 'value', 30);
✗ cache.set('key', 'value', {expiration: 30});
The third parameter is expiration in seconds, not an options object.

Instantiates CacheModule with sessionStorage and default expiration, then performs set, get, and flush operations.

const CacheModule = require('cache-service-cache-module'); const cache = new CacheModule({ storage: 'session', defaultExpiration: 60, verbose: false }); cache.set('key', 'value'); cache.get('key', function(err, result) { if (err) { console.error('Error:', err); return; } console.log('Value:', result); }); cache.flush(function(err) { if (err) { console.error('Flush error:', err); } });
Debug
Known issues
gotchaPackage name does not match npm package name: npm package is 'cache-service-cache-module' but README uses 'cache-service-cache-module' (no hyphen). This can cause confusion when looking up the package.
fix
Use the correct npm package name 'cache-service-cache-module'.
affects: all
gotchaWhen using multiple instances with browser storage, type must be unique. Otherwise, instances overwrite each other's persisted data.
fix
Set a unique 'type' config property for each instance that uses localStorage/sessionStorage.
affects: all
gotchabackgroundRefreshIntervalCheck defaults to true, which throws an error if backgroundRefreshInterval is greater than backgroundRefreshMinTtl. This can break configs that don't follow the constraint.
fix
Ensure backgroundRefreshInterval <= backgroundRefreshMinTtl or set backgroundRefreshIntervalCheck to false.
affects: all
deprecatedThe package has not been updated since 2017. No security patches or API improvements.
fix
Consider migrating to a maintained alternative such as 'cache-manager' or 'node-cache'.
affects: all
Errors
Common errors & fixes
TypeError: cache_service_cache_module is not a constructor
Incorrect import or require path. The module exports a constructor directly, but if imported incorrectly (e.g., expecting .default), it fails.
fix
Use: const CacheModule = require('cache-service-cache-module');
new CacheModule({...});
ReferenceError: localStorage is not defined
Using 'local' or 'session' storage in Node.js environment where browser storage is unavailable.
fix
Do not set storage config in Node.js; it will default to in-memory cache. Or conditionally set storage only in browser.
Error: backgroundRefreshInterval cannot be greater than backgroundRefreshMinTtl
backgroundRefreshIntervalCheck is true (default) and interval > minTtl.
fix
Set backgroundRefreshInterval to a value <= backgroundRefreshMinTtl, or set backgroundRefreshIntervalCheck: false.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
20
Resources
cache-service-cache-module — npm install cache-service-cache-module · libregistry