Registry / web-framework / memoizerific

memoizerific

JSON →
library1.11.3jsnpmunverified

Memoizerific is a fast, small, and efficient JavaScript memoization library designed to cache function results, preventing re-execution for identical arguments. Currently at version 1.11.3, it receives regular minor updates, with recent changes focusing on package configuration and documentation. A key differentiator is its use of JavaScript's native `Map()` object (with a performant polyfill where unavailable) for instant lookups, avoiding costly serialization or string manipulation common in other memoization approaches. It supports multiple complex arguments and incorporates Least-Recently-Used (LRU) caching, allowing developers to specify a limit on the number of results stored. The library is built for compatibility across both browser and Node.js environments and is particularly useful in scenarios like Redux for deriving data on the fly. Its small footprint (1kb min/gzip) makes it a lightweight choice.

npm install memoizerific
INSTALL
IMPORT
SIG · MEMOIZERIFIC
M
memoizerific
web-frameworkjavascriptv1.11.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

memoizerific
import memoizerific from 'memoizerific'
import { memoizerific } from 'memoizerific'
The library exports a factory function as its default export. Named imports will result in `undefined`.
memoizerific (CJS)
const memoizerific = require('memoizerific')
Standard CommonJS import pattern. This is a factory function that takes a limit and returns another function to memoize your target function.
memoizedFunction
const memoized = memoizerific(50)(myFunction);
After importing the `memoizerific` factory, it must be called with a `limit` argument, which then returns a second function to be called with the actual target function (`myFunction`) to be memoized.

This quickstart demonstrates how to initialize Memoizerific with an LRU cache limit and memoize a function. It shows cache hits for identical primitive and complex arguments (same object instance).

import memoizerific from 'memoizerific'; // memoize the 50 most recent argument combinations of our function const memoized = memoizerific(50)(function(arg1, arg2, arg3) { // Simulate a long expensive call console.log(`Processing with args: ${arg1}, ${arg2}, ${arg3}`); let sum = 0; for(let i=0; i<1000000; i++) sum += i; // busy loop return `Result for ${arg1}, ${arg2}, ${arg3}: ${sum}`; }); console.log(memoized(1, 2, 3)); // that took long to process console.log(memoized(1, 2, 3)); // this one was instant! const complexArg1 = { a: { b: { c: 99 }}}, complexArg2 = [{ z: 1}, { q: [{ x: 3 }]}], complexArg3 = new Set(); console.log(memoized(complexArg1, complexArg2, complexArg3)); // slow console.log(memoized(complexArg1, complexArg2, complexArg3)); // instant!
Debug
Known issues
gotchaArguments passed to a memoized function are compared using strict equality (`===`). For objects and arrays, this means they must refer to the exact same instance in memory to trigger a cache hit, not just have identical properties or content. Creating new object/array literals on each call will result in cache misses.
fix
Ensure that complex arguments passed to a memoized function are stable references if you expect cache hits. If deep equality comparison is required, you might need a different memoization library or pre-process your arguments into a stable, serializable key.
affects: >=1.0.0
gotchaSetting the cache `limit` argument to `0` will result in infinite caching. While sometimes desired, this can lead to unbounded memory consumption, especially in long-running applications or with functions called frequently with varied arguments, potentially causing memory leaks or out-of-memory errors.
fix
Always specify a reasonable `limit` for the LRU cache based on your application's needs and memory constraints. Carefully monitor memory usage if using a limit of `0`.
affects: >=1.0.0
breakingIn version 1.10.0, the `main` field in `package.json` was changed to point to the source file (`index.js`) rather than a pre-compiled distribution file, and a new `browser` field was added. While intended to improve compatibility, this change *could* potentially break older bundlers or custom build setups that relied on the previous `main` entry pointing to a pre-compiled output, or setups that don't correctly resolve `browser` fields.
fix
If experiencing unexpected build issues after upgrading to v1.10.0 or later, ensure your bundler (e.g., Webpack, Rollup, Parcel) is configured correctly to handle `package.json` `main` and `browser` fields. You may need to update bundler configurations or dependencies, or explicitly import a specific distribution file from the `dist` directory if available and required by your build process.
affects: >=1.10.0
Errors
Common errors & fixes
TypeError: memoizedFunction is not a function
This error typically occurs if `memoizerific` is not correctly imported as a default export, or if the factory pattern `memoizerific(limit)(fn)` is not followed, leading to an attempt to call a non-function.
fix
Ensure `memoizerific` is imported as a default export (e.g., `import memoizerific from 'memoizerific';` for ESM or `const memoizerific = require('memoizerific');` for CJS) and that it's correctly used in the `memoizerific(limit)(yourFunction)` pattern.
My memoized function keeps running even with identical object arguments!
Memoizerific uses strict equality (`===`) for argument comparison. If you are passing new object or array instances to your memoized function on each call, even if their contents are identical, they are considered different arguments by the cache.
fix
To get a cache hit with complex arguments (objects, arrays), you must pass the exact same object reference to the memoized function. Ensure your object/array arguments are stable (i.e., not new instances created on every render or function call).
Upgrade
Version history
1.11.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
memoizerific — npm install memoizerific · libregistry