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 memoizerificVerified import paths — ran on the pinned version, not inferred.
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).
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.
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`.
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.
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.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).
No dependency data recorded yet.