{"id":44498,"library":"cache-service-cache-module","title":"cache-service-cache-module","description":"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.","status":"maintenance","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/jpodwys/cache-service-cache-module","tags":["javascript","cache-service","cache","node","cache-module","localStorage","sessionStorage","browser"],"install":[{"cmd":"npm install cache-service-cache-module","lang":"bash","label":"npm"},{"cmd":"yarn add cache-service-cache-module","lang":"bash","label":"yarn"},{"cmd":"pnpm add cache-service-cache-module","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package uses CommonJS; ESM import may fail or require default interop.","wrong":"import CacheModule from 'cache-service-cache-module';","symbol":"CacheModule","correct":"const CacheModule = require('cache-service-cache-module');"},{"note":"No .default export; require returns the constructor directly.","wrong":"const CacheModule = require('cache-service-cache-module').default;","symbol":"CacheModule with config","correct":"const CacheModule = require('cache-service-cache-module');\nconst cache = new CacheModule({storage: 'session', defaultExpiration: 60});"},{"note":"The third parameter is expiration in seconds, not an options object.","wrong":"cache.set('key', 'value', {expiration: 30});","symbol":".set()","correct":"cache.set('key', 'value', 30);"}],"quickstart":{"code":"const CacheModule = require('cache-service-cache-module');\n\nconst cache = new CacheModule({\n  storage: 'session',\n  defaultExpiration: 60,\n  verbose: false\n});\n\ncache.set('key', 'value');\n\ncache.get('key', function(err, result) {\n  if (err) {\n    console.error('Error:', err);\n    return;\n  }\n  console.log('Value:', result);\n});\n\ncache.flush(function(err) {\n  if (err) {\n    console.error('Flush error:', err);\n  }\n});","lang":"javascript","description":"Instantiates CacheModule with sessionStorage and default expiration, then performs set, get, and flush operations."},"warnings":[{"fix":"Use the correct npm package name 'cache-service-cache-module'.","message":"Package 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.","severity":"gotcha","affected_versions":"all"},{"fix":"Set a unique 'type' config property for each instance that uses localStorage/sessionStorage.","message":"When using multiple instances with browser storage, type must be unique. Otherwise, instances overwrite each other's persisted data.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure backgroundRefreshInterval <= backgroundRefreshMinTtl or set backgroundRefreshIntervalCheck to false.","message":"backgroundRefreshIntervalCheck defaults to true, which throws an error if backgroundRefreshInterval is greater than backgroundRefreshMinTtl. This can break configs that don't follow the constraint.","severity":"gotcha","affected_versions":"all"},{"fix":"Consider migrating to a maintained alternative such as 'cache-manager' or 'node-cache'.","message":"The package has not been updated since 2017. No security patches or API improvements.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"search_vec":"'2.0.1':32 'altern':65 'api':52 'back':26 'background':45 'browser':77,93 'cach':2,4,8,13,16,24,57,62,72,84,86,89 'cache-modul':88 'cache-servic':15,56,71,83 'cache-service-cache-modul':1 'cadenc':41 'compar':63 'compat':54 'depend':81 'ecosystem':74 'expir':50 'extern':80 'in-memori':21 'integr':67 'javascript':82 'key':49 'latest':35 'lightweight':7 'localstorag':28,91 'memori':23 'modul':5,90 'node':87 'note':42 'option':25 'per':48 'per-key':47 'plugin':9 'provid':44 'refresh':46 'releas':37,40 'robust':51 'servic':3,17,58,73,85 'sessionstorag':30,92 'stabl':36 'standalon':20 'storag':78 'superag':12,61 'superagent-cach':11,60 'support':76 'tight':68 'version':31 'without':79","created_at":"2026-06-07T12:50:25.998792+00:00","updated_at":"2026-06-07T12:50:25.998792+00:00","problems":[{"fix":"Use: const CacheModule = require('cache-service-cache-module');\nnew CacheModule({...});","cause":"Incorrect import or require path. The module exports a constructor directly, but if imported incorrectly (e.g., expecting .default), it fails.","error":"TypeError: cache_service_cache_module is not a constructor"},{"fix":"Do not set storage config in Node.js; it will default to in-memory cache. Or conditionally set storage only in browser.","cause":"Using 'local' or 'session' storage in Node.js environment where browser storage is unavailable.","error":"ReferenceError: localStorage is not defined"},{"fix":"Set backgroundRefreshInterval to a value <= backgroundRefreshMinTtl, or set backgroundRefreshIntervalCheck: false.","cause":"backgroundRefreshIntervalCheck is true (default) and interval > minTtl.","error":"Error: backgroundRefreshInterval cannot be greater than backgroundRefreshMinTtl"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/jpodwys/cache-service-cache-module#readme","github":"https://github.com/jpodwys/cache-service-cache-module","docs":null,"changelog":null,"pypi":null,"npm":"cache-service-cache-module","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}