Registry / storage / pure-cache

pure-cache

JSON →
library1.0.6jsnpmunverified

An ultra fast in-memory JavaScript cache library (~1.28KB gzipped) with near real-time cache expiry, suitable for Node.js and browser environments. Version 1.0.6 is the latest; the library is stable with no frequent updates. Key differentiators: tiny size, event-driven expiry notification, and support for CommonJS and ESM. Alternatives like node-cache or lru-cache are heavier.

npm install pure-cache
INSTALL
IMPORT
SIG · PURE-CACHE
P
pure-cache
storagejavascriptv1.0.6
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.

PureCache
import PureCache from 'pure-cache'
import { PureCache } from 'pure-cache'
Default export only. Named import will result in undefined.
PureCache (CommonJS)
const PureCache = require('pure-cache')
const { PureCache } = require('pure-cache')
CommonJS default export is the constructor itself, not a named export.
UMD global
const PureCache = window.PureCache
When using the UMD build, the library attaches to window as PureCache.

Shows creating a cache instance, setting expiry listener, putting and getting a value, and handling expiry.

import PureCache from 'pure-cache'; const cache = new PureCache({ expiryCheckInterval: 500 }); cache.on('expiry', ({ key, data }) => { console.log(`Key ${key} expired with value ${data.value}`); }); cache.put('greeting', 'Hello', 3000); // expires after 3 seconds console.log(cache.get('greeting')); // { value: 'Hello', addedAt: ..., expiryAt: ... } setTimeout(() => { console.log(cache.get('greeting')); // null after 3 seconds cache.dispose(); }, 4000);
Debug
Known issues
gotchaExpiry check interval (expiryCheckInterval) must be set to a reasonable value. If not set, the default is 1000ms, but if set too high, expired items may linger.
fix
Set expiryCheckInterval to a value lower than your shortest TTL to ensure timely removal.
affects: >=1.0.0
gotchaMemory leak: not calling cache.dispose() when done can leave the expiry checker running indefinitely.
fix
Call cache.dispose() to clear timers and listeners.
affects: >=1.0.0
gotchaEvent listeners persist after disposal? The library does not automatically remove listeners on dispose; you must manually remove them.
fix
Use cache.off('expiry', handler) before dispose or use a one-time listener.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: PureCache is not a constructor
Using named import instead of default import (e.g., import { PureCache } from 'pure-cache').
fix
Use import PureCache from 'pure-cache' or const PureCache = require('pure-cache').
Cannot find module 'pure-cache'
Package not installed or incorrect import path.
fix
Run npm install pure-cache and ensure the import path is correct.
UnhandledPromiseRejectionWarning: TypeError: cacheStore.on is not a function
Forgetting to instantiate with new; using PureCache.on instead of instance.on.
fix
Create an instance: const cache = new PureCache({...}); cache.on(...).
Upgrade
Version history
1.0.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

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