Registry / storage / adequate-cache

adequate-cache

JSON →
library1.1.0jsnpmunverified

A lightweight, in-memory Node.js cache library with LRU eviction and TTL support, written in TypeScript (types included). Current stable version is 1.1.0 (released 2021-10-14). It has zero dependencies, a simple synchronous API (get/set/del/has/keys), and an optional async 'provider' helper to reduce boilerplate for cache-aside patterns. Unlike more complex caching solutions (e.g., node-cache or lru-cache), it focuses on a minimal, intuitive interface with full TypeScript typings. Release cadence is low (a few updates per year).

npm install adequate-cache
INSTALL
IMPORT
SIG · ADEQUATE-CACHE
A
adequate-cache
storagejavascriptv1.1.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.

AdequateCache
import { AdequateCache } from 'adequate-cache'
import AdequateCache from 'adequate-cache'
Named export, not default. For CommonJS use const { AdequateCache } = require('adequate-cache')
CacheOptions
import { CacheOptions } from 'adequate-cache'
import { Options } from 'adequate-cache'
Type import for constructor options
AdequateCache (CommonJS)
const { AdequateCache } = require('adequate-cache')
const AdequateCache = require('adequate-cache')
CommonJS users must destructure the object; the default export is an object with a named property 'AdequateCache'

Demonstrates basic synchronous cache operations and the async provider pattern

import { AdequateCache } from 'adequate-cache'; const cache = new AdequateCache({ max: 10, // maximum number of keys before LRU eviction ttl: 1000 // default TTL in ms (optional) }); cache.set('key1', 'hello'); cache.set('key2', 'world', 2000); // per-key TTL overrides default console.log(cache.get('key1')); // 'hello' console.log(cache.has('key2')); // true cache.del('key1'); console.log(cache.has('key1')); // false // Iterate keys for (const key of cache.keys()) { console.log(key); } // Async provider pattern const provider = async (id) => fetch(`https://api.example.com/users/${id}`).then(r => r.json()); const userCache = new AdequateCache({ provider }); userCache.provide('123').then(user => console.log(user));
Debug
Known issues
breakingv1.0.0 rewrite in TypeScript: the default export changed to named export. CommonJS require must destructure.
fix
Change 'const AdequateCache = require('adequate-cache')' to 'const { AdequateCache } = require('adequate-cache')' or use ESM import { AdequateCache } from 'adequate-cache'
affects: >=0.x <=0.4.1
gotchaset() with undefined value deletes the key; it does not store undefined.
fix
Do not use undefined as a value. Use null or another sentinel if needed.
affects: >=0.1.0
deprecatedProvider promises are reused since v0.4.0; calling cache.provide with the same key while another request is pending will return the same promise.
fix
Upgrade to >=0.4.0 for promise deduplication
affects: <0.4.0
gotchaAll keys are coerced to strings. Setting a numeric key will be stored as string.
fix
Always use string keys to avoid unexpected coercion
affects: >=0.1.0
Errors
Common errors & fixes
ReferenceError: AdequateCache is not defined
CommonJS require without destructuring: const AdequateCache = require('adequate-cache')
fix
Use const { AdequateCache } = require('adequate-cache') or import { AdequateCache } from 'adequate-cache'
Cannot find module 'adequate-cache'
Package not installed or import path incorrect
fix
Run npm install adequate-cache or yarn add adequate-cache
cache.provide is not a function
Attempting to use provider without setting 'provider' in constructor options
fix
Create the cache with new AdequateCache({ provider: yourAsyncFn })
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
42 hits · last 30 days
node
34
OpenAI (training)
1
Resources
adequate-cache — npm install adequate-cache · libregistry