Registry / storage / limited-cache

limited-cache

JSON →
library2.2.0jsnpmunverified

A minimal JS cache that prevents unbounded growth by enforcing a size limit and optional max age. Version 2.2.0 actively maintained on GitHub. Provides three API tiers: a standard class-based interface (LimitedCache), a Proxy-based object-style API (LimitedCacheObject), and low-level serializable functions for offline/Redux use. Ships TypeScript definitions. Unlike simple object caches, it uses a circular buffer for efficient eviction and warns in development if items are evicted prematurely.

npm install limited-cache
INSTALL
IMPORT
SIG · LIMITED-CACHE
L
limited-cache
storagejavascriptv2.2.0
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.

LimitedCache
import { LimitedCache } from 'limited-cache'
const LimitedCache = require('limited-cache')
Default export not available; must use named import.
LimitedCacheObject
import { LimitedCacheObject } from 'limited-cache'
Proxy-based API that allows bracket notation like a plain object.
limitedCacheUtil
import { limitedCacheUtil } from 'limited-cache'
import limitedCacheUtil from 'limited-cache'
The low-level utility object is a named export, not default.

Shows basic usage of LimitedCache: creation with options, set, get, has, getAll, and reset.

import { LimitedCache } from 'limited-cache'; const cache = LimitedCache({ maxCacheSize: 10, maxCacheTime: 60000 }); cache.set('key1', { data: 'value' }); const result = cache.get('key1'); console.log(result); // { data: 'value' } console.log(cache.has('key1')); // true console.log(cache.getAll()); // { key1: { data: 'value' } } cache.reset(); console.log(cache.has('key1')); // false
Debug
Known issues
breakingReact hooks useLimitedCache and useLimitedCacheObject were removed in v1.0.0.
fix
Use useMemo(() => LimitedCache(), []) instead, or copy the hooks from the old source.
affects: >=1.0.0
gotchamaxCacheTime default is 1 day (86400000 ms) and maximum is 1 year (31536000000 ms). Setting maxCacheTime to a falsy value disables time-based eviction but sets it to the 1-year maximum, not unlimited.
fix
Set maxCacheTime to 0 or null only if you want the maximum 1-year expiry. For true unlimited time, set a very large number (but note it's capped at 1 year).
affects: all
gotchawarnIfItemPurgedBeforeTime is only effective in development mode. In production, warnings are suppressed.
fix
Use for development tuning only; do not rely on it in production.
affects: all
deprecatedlow-level function names (lowLevelInit, lowLevelGetOne, etc.) are stable but less convenient than the class/object API.
fix
Prefer LimitedCache or LimitedCacheObject for most use cases; use low-level only when you need serialization (e.g., Redux).
affects: all
gotchaLimitedCacheObject uses a Proxy and may not work in older environments (IE11) without a Proxy polyfill.
fix
Use LimitedCache instead if Proxy is unavailable.
affects: all
Errors
Common errors & fixes
TypeError: limitedCacheUtil is not a function
Importing limitedCacheUtil as default export instead of named.
fix
Change to: import { limitedCacheUtil } from 'limited-cache'
Uncaught TypeError: Cannot use 'in' operator to search for 'key1' in undefined
Accessing cache property on LimitedCacheObject that was not initialized correctly.
fix
Ensure you call LimitedCacheObject() as a function: const cache = LimitedCacheObject();
Module not found: Error: Can't resolve 'limited-cache'
Package not installed or import path incorrect.
fix
Run: npm install limited-cache
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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