Registry / testing / cachewrap

cachewrap

JSON →
library0.0.1jsnpmunverified

A minimal utility to cache the return value of a function based on its arguments. v0.0.1 is pre-1.0.0 with an unstable API. It provides a simple way to memoize function calls with an optional custom hash function and a .refresh method to bypass cache. No dependencies. Not actively maintained; last update long ago.

npm install cachewrap
INSTALL
IMPORT
SIG · CACHEWRAP
C
cachewrap
testingjavascriptv0.0.1
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.

createCacheWrap
import createCacheWrap from 'cachewrap'
const { createCacheWrap } = require('cachewrap')
The package exports a single function as default. Use default import or require the module directly.
createCacheWrap (CommonJS)
const createCacheWrap = require('cachewrap')
const createCacheWrap = require('cachewrap').createCacheWrap
In CommonJS, require('cachewrap') returns the function directly.
Wrapped function
const wrapped = cacheWrap(fn)
const wrapped = new cacheWrap(fn)
cacheWrap returns a wrapped function, not a constructor. Do not use 'new'.

Shows how to wrap a function with cachewrap and use forced refresh via the .refresh method.

const createCacheWrap = require('cachewrap') const cacheWrap = createCacheWrap() function random(min: number, max: number): number { return Math.random() * (max - min) + min } const wrappedRandom = cacheWrap(random) console.log(wrappedRandom(10, 100)) // e.g., 45.123 console.log(wrappedRandom(10, 100)) // same result due to cache console.log(wrappedRandom.refresh(10, 100)) // different result
Debug
Known issues
deprecatedPackage is unmaintained with no updates since initial release. Use at own risk.
fix
Consider alternatives like memoizee or lodash.memoize.
affects: >=0.0.0
gotchaDefault hash function uses params.map(p => p.toString()).join() which can produce collisions for objects.
fix
Pass a custom hash function that handles deep equality or serialization properly.
affects: -
gotchaThe package does not support TTL (time-to-live) cache expiration.
fix
If you need cache expiry, use a different library like memoizee.
affects: -
breakingPre-1.0.0 versions may contain breaking changes without major version bump.
fix
Pin to exact version in package.json: 'cachewrap': '0.0.1'
affects: <1.0.0
Errors
Common errors & fixes
TypeError: createCacheWrap is not a function
Named import instead of default import in ESM.
fix
Use 'import createCacheWrap from "cachewrap"' or 'const createCacheWrap = require("cachewrap")'
Cannot find module 'cachewrap'
Package not installed or case sensitivity in require/import path.
fix
Run 'npm install cachewrap' and ensure path is exactly 'cachewrap'.
wrappedRandom(...) !== wrappedRandom(...) (caching not working)
Arguments are objects with different references; default hash uses toString.
fix
Provide a custom hash function that serializes objects (e.g., JSON.stringify).
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
cachewrap — npm install cachewrap · libregistry