{"id":11296,"library":"memoizerific","title":"Memoizerific","description":"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.","status":"active","version":"1.11.3","language":"javascript","source_language":"en","source_url":"https://github.com/thinkloop/memoizerific","tags":["javascript","memoize","memoizer","memoization","memoized","js","lru","cache"],"install":[{"cmd":"npm install memoizerific","lang":"bash","label":"npm"},{"cmd":"yarn add memoizerific","lang":"bash","label":"yarn"},{"cmd":"pnpm add memoizerific","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library exports a factory function as its default export. Named imports will result in `undefined`.","wrong":"import { memoizerific } from 'memoizerific'","symbol":"memoizerific","correct":"import memoizerific from 'memoizerific'"},{"note":"Standard CommonJS import pattern. This is a factory function that takes a limit and returns another function to memoize your target function.","symbol":"memoizerific (CJS)","correct":"const memoizerific = require('memoizerific')"},{"note":"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.","symbol":"memoizedFunction","correct":"const memoized = memoizerific(50)(myFunction);"}],"quickstart":{"code":"import memoizerific from 'memoizerific';\n\n// memoize the 50 most recent argument combinations of our function\nconst memoized = memoizerific(50)(function(arg1, arg2, arg3) {\n    // Simulate a long expensive call\n    console.log(`Processing with args: ${arg1}, ${arg2}, ${arg3}`);\n    let sum = 0;\n    for(let i=0; i<1000000; i++) sum += i; // busy loop\n    return `Result for ${arg1}, ${arg2}, ${arg3}: ${sum}`;\n});\n\nconsole.log(memoized(1, 2, 3)); // that took long to process\nconsole.log(memoized(1, 2, 3)); // this one was instant!\n\nconst \n    complexArg1 = { a: { b: { c: 99 }}}, \n    complexArg2 = [{ z: 1}, { q: [{ x: 3 }]}],\n    complexArg3 = new Set(); \n\nconsole.log(memoized(complexArg1, complexArg2, complexArg3)); // slow\nconsole.log(memoized(complexArg1, complexArg2, complexArg3)); // instant!","lang":"javascript","description":"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)."},"warnings":[{"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.","message":"Arguments 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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`.","message":"Setting 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"In 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.","severity":"breaking","affected_versions":">=1.10.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"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.","error":"TypeError: memoizedFunction is not a function"},{"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).","cause":"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.","error":"My memoized function keeps running even with identical object arguments!"}],"ecosystem":"npm"}