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.
withSimpleCache
✓ import { withSimpleCache } from 'with-simple-cache'
✗ import withSimpleCache from 'with-simple-cache'
Named export only; default import is not available
withSimpleCacheAsync
✓ import { withSimpleCacheAsync } from 'with-simple-cache'
✗ import { withSimpleCacheAsync } from 'with-simple-cache/async'
Exported from main module, not a subpath
type Cache
✓ import type { Cache } from 'with-simple-cache'
✗ import { Cache } from 'with-simple-cache'
Cache is exported as a type for TypeScript users; runtime import will be undefined
Demonstrates synchronous caching: same input returns cached object reference
import { createCache } from 'simple-in-memory-cache';
import { withSimpleCache } from 'with-simple-cache';
const solveSuperToughMathProblem = withSimpleCache(
({ a, b }: { a: number; b: number }) => ({ solution: a + b }),
{ cache: createCache() },
);
const result1 = solveSuperToughMathProblem({ a: 1, b: 1 });
const result2 = solveSuperToughMathProblem({ a: 1, b: 1 });
console.log(result1 === result2); // true
Debug
Known issues
breakingCache argument object shape changed in v0.10.0: was { store, ... } now { cache, ... }fixUse { cache: createCache() } instead of { store: createCache() } affects: >=0.10.0 <0.16.0
gotchaAsync cache usage requires explicit withSimpleCacheAsync wrapper for correct deduplication; using withSimpleCache with async cache may cause stale resultsfixImport withSimpleCacheAsync for async logic with async cache stores
affects: >=0.10.0
deprecatedString literals as cache keys are deprecated in favor of object-based keys (v0.8+)fixPass object arguments to cached function; avoid raw string keys
affects: >=0.8.0
gotchaCache key derivation relies on object identity, not deep equality; mutating input objects after first call will not invalidate cachefixUse immutable patterns or ensure same object references for cache hits
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: cache.set is not a function
Passed an object without the expected cache interface (set, get, has, delete methods) as the cache option
fixUse a cache implementation that provides the required methods, e.g., simple-in-memory-cache
Error: withSimpleCache expects a function as first argument
First argument to withSimpleCache is not a callable function
fixEnsure the first argument is a function expression or arrow function, not a variable reference
TS2339: Property 'withSimpleCacheAsync' does not exist on type 'typeof import("with-simple-cache")'
Trying to use an old import path (with-simple-cache/async) that does not exist
fixImport from the main module: import { withSimpleCacheAsync } from 'with-simple-cache' Audit
Dependencies
simple-in-memory-cacheoptionalRequired for default in-memory cache in examples, but not a package dependency; user provides cache implementation
simple-on-disk-cacheoptionalExample usage for async cache, optional user choice