{"_id":"memoize","_rev":"24-a0963016e308f8cda752787fb52cc43c","name":"memoize","dist-tags":{"latest":"11.0.0"},"versions":{"0.0.1":{"name":"memoize","version":"0.0.1","keywords":["memoize","cache"],"author":{"name":"George Stagas","email":"gstagas@gmail.com"},"_id":"memoize@0.0.1","bugs":{"url":"https://github.com/stagas/memoize/issues"},"dist":{"shasum":"a58167513a0ce451a33db3684ccc27df1760df78","tarball":"https://registry.npmjs.org/memoize/-/memoize-0.0.1.tgz","integrity":"sha512-6XPnORUIJEVirsnqh4My8BFY7w5mCuzXqutm400KuMTco/y7gzN/FOO8pU7jgCmpeSkRGDIiPtCXwFrD6zLLgg==","signatures":[{"sig":"MEQCIHCaNyzoZyaWeUV9IKh+3abs9BLl4XIEzr/R4oSRnpylAiBQkT+gv2YzfadTD21wSqf3ymgGHI4UdLA6/V/udjO/Lg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"./memoize","files":[""],"engines":{"node":"*"},"repository":{"url":"git://github.com/stagas/memoize.git","type":"git"},"_npmVersion":"0.3.18","description":"memoize caches your callbacks given a set of arguments","directories":{},"_nodeVersion":"v0.4.7","_defaultsLoaded":true,"_engineSupported":true},"0.0.2":{"name":"memoize","version":"0.0.2","keywords":["memoize","cache"],"author":{"name":"George Stagas","email":"gstagas@gmail.com"},"_id":"memoize@0.0.2","bugs":{"url":"https://github.com/stagas/memoize/issues"},"dist":{"shasum":"1fec54a625c3b753ea940630cdf33f9b95e3a103","tarball":"https://registry.npmjs.org/memoize/-/memoize-0.0.2.tgz","integrity":"sha512-Y7tUF4lohNUh5i55fJfbg20R/ATJXp8DOH8JW03eEO+JDWLNwphz+ue5BRL6Z0A2gk6GHgNp0d5ygaof8WuflA==","signatures":[{"sig":"MEQCIBoZCcN+VQAKgk97cuXSQflhWiifHIoRQt1jUtVjrK9nAiAJbfBlRKK5x8YsPDBXHuFLe0zT+RKObNFVGwNCH2h7ZQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"./memoize","files":[""],"engines":{"node":"*"},"repository":{"url":"git://github.com/stagas/memoize.git","type":"git"},"_npmVersion":"0.3.18","description":"memoize caches your callbacks given a set of arguments","directories":{},"_nodeVersion":"v0.4.7","_defaultsLoaded":true,"_engineSupported":true},"0.0.3":{"name":"memoize","version":"0.0.3","keywords":["memoize","cache"],"author":{"name":"George Stagas","email":"gstagas@gmail.com"},"_id":"memoize@0.0.3","bugs":{"url":"https://github.com/stagas/memoize/issues"},"dist":{"shasum":"9a7a12ac9b719f7d307fb0882f191664f1ae6a23","tarball":"https://registry.npmjs.org/memoize/-/memoize-0.0.3.tgz","integrity":"sha512-luuX1mfOouXVKy7m8d8Pqi9DqD2AVqjWiPS7fY0AqwvKW8URaHdp7/FW1Grf3qqO1VLddmTtEHYJWrQtRKbSeA==","signatures":[{"sig":"MEQCID0H3WZa6MNewMbve49FSPsSWcj7UZIsfOEJDgGTIMzjAiAm/Eu44+DSAmLKDpfb/CpuA4G9tZxI9+9uvcBacwcEgA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"./memoize","files":[""],"engines":{"node":"*"},"repository":{"url":"git://github.com/stagas/memoize.git","type":"git"},"_npmVersion":"0.3.18","description":"memoize caches your callbacks given a set of arguments","directories":{},"_nodeVersion":"v0.4.7","dependencies":{"tosource":">=0.1.1"},"_defaultsLoaded":true,"_engineSupported":true},"0.1.0":{"name":"memoize","version":"0.1.0","keywords":["memoize","cache"],"author":{"name":"George Stagas","email":"gstagas@gmail.com"},"_id":"memoize@0.1.0","maintainers":[{"name":"stagas","email":"gstagas@gmail.com"}],"bugs":{"url":"https://github.com/stagas/memoize/issues"},"dist":{"shasum":"61c1037a0ca916ff4d33cd84db554d4988b96925","tarball":"https://registry.npmjs.org/memoize/-/memoize-0.1.0.tgz","integrity":"sha512-xSV/R14UMpEE2xOJcGwt1bWL502r/hrduIVW/3rFGriW1PTHWvwEpHF3jIA4PjPAbWm5eHpU2oBsqyInx5rDSA==","signatures":[{"sig":"MEQCIAgkLuT9U4ALXt1LwjMaEay6brXZBSV4lBj5FGobSvQ1AiBN2skxfWyn28QEH5BSuZIj9GIhV1YmcPjcYT37hujcNQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"./memoize","files":[""],"engines":{"node":"*"},"repository":{"url":"git://github.com/stagas/memoize.git","type":"git"},"_npmVersion":"0.3.18","description":"memoize caches your callbacks given a set of arguments w/ persistence","directories":{},"_nodeVersion":"v0.4.8","dependencies":{"tosource":">=0.1.1"},"_defaultsLoaded":true,"_engineSupported":true},"0.1.1":{"name":"memoize","version":"0.1.1","keywords":["memoize","cache"],"author":{"name":"George Stagas","email":"gstagas@gmail.com"},"_id":"memoize@0.1.1","maintainers":[{"name":"stagas","email":"gstagas@gmail.com"}],"bugs":{"url":"https://github.com/stagas/memoize/issues"},"dist":{"shasum":"d265a3458be5ce3bf254998b30a995ab91668a24","tarball":"https://registry.npmjs.org/memoize/-/memoize-0.1.1.tgz","integrity":"sha512-6XjEiKKylCv6AV9ZwNGauIGqS46mf/I2Zg466Z2yR1kcDzzSjVOdsW5EwGeaa3KT57n+WY41mVPmh+2dqLs6bQ==","signatures":[{"sig":"MEUCIBrZne33OX41bqPqBAf8U7WRruh44ei87pODeauyyOX1AiEA3BRlGQhPrvUcj/NfOdBkPF4ZyBGKpko2J34lotLkX8k=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"./memoize","files":[""],"engines":{"node":"*"},"repository":{"url":"git://github.com/stagas/memoize.git","type":"git"},"_npmVersion":"0.3.18","description":"memoize caches your callbacks given a set of arguments w/ persistence","directories":{},"_nodeVersion":"v0.4.8","dependencies":{"tosource":">=0.1.1"},"_defaultsLoaded":true,"_engineSupported":true},"10.0.0":{"name":"memoize","version":"10.0.0","keywords":["memoize","function","mem","memoization","cache","caching","optimize","performance","ttl","expire","promise"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"memoize@10.0.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"homepage":"https://github.com/sindresorhus/memoize#readme","bugs":{"url":"https://github.com/sindresorhus/memoize/issues"},"xo":{"rules":{"@typescript-eslint/no-unsafe-return":"off"}},"ava":{"timeout":"1m","extensions":{"ts":"module"},"nodeArguments":["--loader=ts-node/esm"]},"dist":{"shasum":"43fa66b2022363c7c50cf5dfab732a808a3d7147","tarball":"https://registry.npmjs.org/memoize/-/memoize-10.0.0.tgz","fileCount":5,"integrity":"sha512-H6cBLgsi6vMWOcCpvVCdFFnl3kerEXbrYh9q+lY6VXvQSmM6CkmV08VOwT+WE2tzIEqRPFfAq3fm4v/UIW6mSA==","signatures":[{"sig":"MEYCIQDHKQATvwO767w18zWGnXbZ0kokf3n+40E+FFbTNS7zYQIhAOo1IPcJ0SvyISEnYK8wrCI1+PHX9I5m4ZyrpYhg2nt/","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":18417},"type":"module","engines":{"node":">=18"},"exports":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"funding":"https://github.com/sindresorhus/memoize?sponsor=1","gitHead":"2a8997ededd818a07edab1a750cf969ba473de3c","scripts":{"test":"xo && ava && npm run build && tsd --typings dist/index.d.ts","build":"del-cli dist && tsc","prepack":"npm run build"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/memoize.git","type":"git"},"_npmVersion":"9.2.0","description":"Memoize functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input","directories":{},"sideEffects":false,"_nodeVersion":"18.18.2","dependencies":{"mimic-function":"^5.0.0"},"_hasShrinkwrap":false,"devDependencies":{"xo":"^0.56.0","ava":"^5.3.1","tsd":"^0.29.0","delay":"^6.0.0","del-cli":"^5.1.0","ts-node":"^10.9.1","serialize-javascript":"^6.0.1","@sindresorhus/tsconfig":"^5.0.0","@types/serialize-javascript":"^5.0.4"},"_npmOperationalInternal":{"tmp":"tmp/memoize_10.0.0_1699976814316_0.694652217839381","host":"s3://npm-registry-packages"}},"10.1.0":{"name":"memoize","version":"10.1.0","keywords":["memoize","function","mem","memoization","cache","caching","optimize","performance","ttl","expire","promise"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"memoize@10.1.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"homepage":"https://github.com/sindresorhus/memoize#readme","bugs":{"url":"https://github.com/sindresorhus/memoize/issues"},"xo":{"rules":{"@typescript-eslint/no-unsafe-return":"off"}},"ava":{"timeout":"1m","extensions":{"ts":"module"},"nodeArguments":["--loader=ts-node/esm"],"workerThreads":false},"dist":{"shasum":"32a9d09da985a1ab518dfe9fd52d14d1d130446f","tarball":"https://registry.npmjs.org/memoize/-/memoize-10.1.0.tgz","fileCount":5,"integrity":"sha512-MMbFhJzh4Jlg/poq1si90XRlTZRDHVqdlz2mPyGJ6kqMpyHUyVpDd5gpFAvVehW64+RA1eKE9Yt8aSLY7w2Kgg==","signatures":[{"sig":"MEUCICfUGY6Fq+CAWcf7yFSM9rprSwdN97H6zf70dUFYAGDUAiEAh++wLKYJB4j/tIqWeFsZzqHvNujC6lyuFwe48bTF4qU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":19083},"type":"module","engines":{"node":">=18"},"exports":{"types":"./distribution/index.d.ts","default":"./distribution/index.js"},"funding":"https://github.com/sindresorhus/memoize?sponsor=1","gitHead":"e96965cf6ffc9af784bdebab6eef408d017a6620","scripts":{"test":"xo && ava && npm run build && tsd --typings distribution/index.d.ts","build":"del-cli distribution && tsc","prepack":"npm run build"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/memoize.git","type":"git"},"_npmVersion":"10.9.2","description":"Memoize functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input","directories":{},"sideEffects":false,"_nodeVersion":"23.6.1","dependencies":{"mimic-function":"^5.0.1"},"_hasShrinkwrap":false,"devDependencies":{"xo":"^0.59.3","ava":"^6.1.3","tsd":"^0.31.1","delay":"^6.0.0","del-cli":"^5.1.0","ts-node":"^10.9.2","serialize-javascript":"^6.0.2","@sindresorhus/tsconfig":"^6.0.0","@types/serialize-javascript":"^5.0.4"},"_npmOperationalInternal":{"tmp":"tmp/memoize_10.1.0_1739960320380_0.03932131984779752","host":"s3://npm-registry-packages-npm-production"}},"10.2.0":{"name":"memoize","version":"10.2.0","keywords":["memoize","function","mem","memoization","cache","caching","optimize","performance","ttl","expire","promise"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"memoize@10.2.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"homepage":"https://github.com/sindresorhus/memoize#readme","bugs":{"url":"https://github.com/sindresorhus/memoize/issues"},"xo":{"rules":{"@typescript-eslint/no-unsafe-return":"off"}},"ava":{"timeout":"1m","extensions":{"ts":"module"},"nodeArguments":["--loader=ts-node/esm"],"workerThreads":false},"dist":{"shasum":"593f8066b922b791390d05e278dbeff163dad956","tarball":"https://registry.npmjs.org/memoize/-/memoize-10.2.0.tgz","fileCount":5,"integrity":"sha512-DeC6b7QBrZsRs3Y02A6A7lQyzFbsQbqgjI6UW0GigGWV+u1s25TycMr0XHZE4cJce7rY/vyw2ctMQqfDkIhUEA==","signatures":[{"sig":"MEQCIDa8T303ckm09bq1btuq3++Me6m4E1i+R9zg7m59wfi6AiAg8uQiuQF98wbxZiwR8AOsO5qwiZYdknJLLyAuhEN4rA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":22885},"type":"module","engines":{"node":">=18"},"exports":{"types":"./distribution/index.d.ts","default":"./distribution/index.js"},"funding":"https://github.com/sindresorhus/memoize?sponsor=1","gitHead":"4c2b35fad5841cea20274b461fe2528fa40a692d","scripts":{"test":"xo && ava && npm run build && tsd --typings distribution/index.d.ts","build":"del-cli distribution && tsc","prepack":"npm run build"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/memoize.git","type":"git"},"_npmVersion":"11.6.1","description":"Memoize functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input","directories":{},"sideEffects":false,"_nodeVersion":"24.9.0","dependencies":{"mimic-function":"^5.0.1"},"_hasShrinkwrap":false,"devDependencies":{"xo":"^0.59.3","ava":"^6.1.3","tsd":"^0.31.1","delay":"^6.0.0","del-cli":"^5.1.0","ts-node":"^10.9.2","serialize-javascript":"^6.0.2","@sindresorhus/tsconfig":"^6.0.0","@types/serialize-javascript":"^5.0.4"},"_npmOperationalInternal":{"tmp":"tmp/memoize_10.2.0_1761319108609_0.36495026127893704","host":"s3://npm-registry-packages-npm-production"}},"11.0.0":{"name":"memoize","version":"11.0.0","description":"Memoize functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/memoize.git"},"funding":"https://github.com/sindresorhus/memoize?sponsor=1","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./distribution/index.d.ts","default":"./distribution/index.js"},"sideEffects":false,"engines":{"node":">=22"},"scripts":{"test":"xo && ava && npm run build && tsd --typings distribution/index.d.ts","build":"del-cli distribution && tsc","prepack":"npm run build"},"keywords":["memoize","function","mem","memoization","cache","caching","optimize","performance","ttl","expire","promise"],"dependencies":{"mimic-function":"^5.0.1"},"devDependencies":{"@sindresorhus/tsconfig":"^8.1.0","@types/serialize-javascript":"^5.0.4","ava":"^7.0.0","del-cli":"^7.0.0","delay":"^7.0.0","serialize-javascript":"^7.0.4","tsd":"^0.33.0","tsimp":"^2.0.12","xo":"^2.0.2"},"ava":{"timeout":"1m","extensions":{"ts":"module"},"nodeArguments":["--import=tsimp"],"workerThreads":false,"environmentVariables":{"TSIMP_DIAG":"ignore"}},"xo":{"rules":{"@typescript-eslint/no-unsafe-call":"off","@typescript-eslint/no-unsafe-member-access":"off","@typescript-eslint/no-unsafe-return":"off","@typescript-eslint/no-unsafe-type-assertion":"off"}},"gitHead":"7821ca06700dd13909e7bc71a1193e40f2611297","_id":"memoize@11.0.0","bugs":{"url":"https://github.com/sindresorhus/memoize/issues"},"homepage":"https://github.com/sindresorhus/memoize#readme","_nodeVersion":"25.8.0","_npmVersion":"11.11.0","dist":{"integrity":"sha512-cjsfZaC9b1clqPeIVMbb5dLHSXgdgGWGxdAU3oTUUkHiwWTKTBNnSmcqWJncNjYtBi3S8Rp0c5GIiyGztR8TRA==","shasum":"8472a09bb0457ccbe4e3034ace0fbeeb30a13f7d","tarball":"https://registry.npmjs.org/memoize/-/memoize-11.0.0.tgz","fileCount":5,"unpackedSize":26677,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCj+5VQcVrnrkH7Pfw7i1tITTR7qZiX2mjzCU2AwbfTTQIhAIA8ImrQCFDvDSO6eK9tV8lKTJ42p8A+ydi5t327byix"}]},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/memoize_11.0.0_1773908466783_0.46798211736934037"},"_hasShrinkwrap":false}},"time":{"created":"2011-05-05T14:50:14.538Z","modified":"2026-03-19T08:21:07.043Z","0.0.1":"2011-05-05T14:50:18.269Z","0.0.2":"2011-05-05T15:03:55.184Z","0.0.3":"2011-05-05T15:41:19.446Z","0.1.0":"2011-08-23T08:03:57.298Z","0.1.1":"2011-08-23T09:16:11.620Z","10.0.0":"2023-11-14T15:46:54.475Z","10.1.0":"2025-02-19T10:18:40.555Z","10.2.0":"2025-10-24T15:18:28.819Z","11.0.0":"2026-03-19T08:21:06.926Z"},"bugs":{"url":"https://github.com/sindresorhus/memoize/issues"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"license":"MIT","homepage":"https://github.com/sindresorhus/memoize#readme","keywords":["memoize","function","mem","memoization","cache","caching","optimize","performance","ttl","expire","promise"],"repository":{"type":"git","url":"git+https://github.com/sindresorhus/memoize.git"},"description":"Memoize functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"readme":"# memoize\n\n> [Memoize](https://en.wikipedia.org/wiki/Memoization) functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input\n\nMemory is automatically released when an item expires or the cache is cleared.\n\n<!-- Please keep this section in sync with https://github.com/sindresorhus/p-memoize/blob/main/readme.md -->\n\nBy default, **only the memoized function's first argument is considered** via strict equality comparison. If you need to cache multiple arguments or cache `object`s *by value*, have a look at alternative [caching strategies](#caching-strategy) below.\n\nIf you want to memoize Promise-returning functions (like `async` functions), you might be better served by [p-memoize](https://github.com/sindresorhus/p-memoize).\n\n## Install\n\n```sh\nnpm install memoize\n```\n\n## Usage\n\n```js\nimport memoize from 'memoize';\n\nlet index = 0;\nconst counter = () => ++index;\nconst memoized = memoize(counter);\n\nmemoized('foo');\n//=> 1\n\n// Cached as it's the same argument\nmemoized('foo');\n//=> 1\n\n// Not cached anymore as the argument changed\nmemoized('bar');\n//=> 2\n\nmemoized('bar');\n//=> 2\n\n// Only the first argument is considered by default\nmemoized('bar', 'foo');\n//=> 2\n```\n\n##### Works well with Promise-returning functions\n\nBut you might want to use [p-memoize](https://github.com/sindresorhus/p-memoize) for more Promise-specific behaviors.\n\n```js\nimport memoize from 'memoize';\n\nlet index = 0;\nconst counter = async () => ++index;\nconst memoized = memoize(counter);\n\nconsole.log(await memoized());\n//=> 1\n\n// The return value didn't increase as it's cached\nconsole.log(await memoized());\n//=> 1\n```\n\n```js\nimport memoize from 'memoize';\nimport got from 'got';\nimport delay from 'delay';\n\nconst memoizedGot = memoize(got, {maxAge: 1000});\n\nawait memoizedGot('https://sindresorhus.com');\n\n// This call is cached\nawait memoizedGot('https://sindresorhus.com');\n\nawait delay(2000);\n\n// This call is not cached as the cache has expired\nawait memoizedGot('https://sindresorhus.com');\n```\n\n### Caching strategy\n\nBy default, only the first argument is compared via exact equality (`===`) to determine whether a call is identical.\n\n```js\nimport memoize from 'memoize';\n\nconst pow = memoize((a, b) => Math.pow(a, b));\n\npow(2, 2); // => 4, stored in cache with the key 2 (number)\npow(2, 3); // => 4, retrieved from cache at key 2 (number), it's wrong\n```\n\nYou will have to use the `cache` and `cacheKey` options appropriate to your function. In this specific case, the following could work:\n\n```js\nimport memoize from 'memoize';\n\nconst pow = memoize((a, b) => Math.pow(a, b), {\n\tcacheKey: arguments_ => arguments_.join(',')\n});\n\npow(2, 2); // => 4, stored in cache with the key '2,2' (both arguments as one string)\npow(2, 3); // => 8, stored in cache with the key '2,3'\n```\n\nMore advanced examples follow.\n\n#### Example: Options-like argument\n\nIf your function accepts an object, it won't be memoized out of the box:\n\n```js\nimport memoize from 'memoize';\n\nconst heavyMemoizedOperation = memoize(heavyOperation);\n\nheavyMemoizedOperation({full: true}); // Stored in cache with the object as key\nheavyMemoizedOperation({full: true}); // Stored in cache with the object as key, again\n// The objects appear the same, but in JavaScript, they're different objects\n```\n\nYou might want to serialize or hash them, for example using `JSON.stringify` or something like [serialize-javascript](https://github.com/yahoo/serialize-javascript), which can also serialize `RegExp`, `Date` and so on.\n\n```js\nimport memoize from 'memoize';\n\nconst heavyMemoizedOperation = memoize(heavyOperation, {cacheKey: JSON.stringify});\n\nheavyMemoizedOperation({full: true}); // Stored in cache with the key '[{\"full\":true}]' (string)\nheavyMemoizedOperation({full: true}); // Retrieved from cache\n```\n\nThe same solution also works if it accepts multiple serializable objects:\n\n```js\nimport memoize from 'memoize';\n\nconst heavyMemoizedOperation = memoize(heavyOperation, {cacheKey: JSON.stringify});\n\nheavyMemoizedOperation('hello', {full: true}); // Stored in cache with the key '[\"hello\",{\"full\":true}]' (string)\nheavyMemoizedOperation('hello', {full: true}); // Retrieved from cache\n```\n\n#### Example: Multiple non-serializable arguments\n\nIf your function accepts multiple arguments that aren't supported by `JSON.stringify` (e.g. DOM elements and functions), you can instead extend the initial exact equality (`===`) to work on multiple arguments using [`many-keys-map`](https://github.com/fregante/many-keys-map):\n\n```js\nimport memoize from 'memoize';\nimport ManyKeysMap from 'many-keys-map';\n\nconst addListener = (emitter, eventName, listener) => emitter.on(eventName, listener);\n\nconst addOneListener = memoize(addListener, {\n\tcacheKey: arguments_ => arguments_, // Use *all* the arguments as key\n\tcache: new ManyKeysMap() // Correctly handles all the arguments for exact equality\n});\n\naddOneListener(header, 'click', console.log); // `addListener` is run, and it's cached with the `arguments` array as key\naddOneListener(header, 'click', console.log); // `addListener` is not run again because the arguments are the same\naddOneListener(mainContent, 'load', console.log); // `addListener` is run, and it's cached with the `arguments` array as key\n```\n\nBetter yet, if your function’s arguments are compatible with `WeakMap`, you should use [`deep-weak-map`](https://github.com/futpib/deep-weak-map) instead of `many-keys-map`. This will help avoid memory leaks.\n\n## API\n\n### memoize(fn, options?)\n\n#### fn\n\nType: `Function`\n\nThe function to be memoized.\n\n#### options\n\nType: `object`\n\n##### maxAge\n\nType: `number` | `Function`\\\nDefault: `Infinity`\\\nExample: `arguments_ => arguments_ < new Date() ? Infinity : 60_000`\n\nMilliseconds until the cache entry expires.\n\nIf a function is provided, it receives the arguments and must return the max age.\n\n- `0` or negative values: Do not cache the result\n- `Infinity`: Cache indefinitely (no expiration)\n- Positive finite number: Cache for the specified milliseconds\n\n##### cacheKey\n\nType: `Function`\\\nDefault: `arguments_ => arguments_[0]`\\\nExample: `arguments_ => JSON.stringify(arguments_)`\n\nDetermines the cache key for storing the result based on the function arguments. By default, **only the first argument is considered**.\n\nA `cacheKey` function can return any type supported by `Map` (or whatever structure you use in the `cache` option).\n\nRefer to the [caching strategies](#caching-strategy) section for more information.\n\n##### cache\n\nType: `object`\\\nDefault: `new Map()`\n\nUse a different cache storage. Must implement the following methods: `.get(key)`, `.set(key, value)`, `.delete(key)`, and optionally `.clear()`. You could for example use a `WeakMap` instead or [`quick-lru`](https://github.com/sindresorhus/quick-lru) for a LRU cache.\n\nRefer to the [caching strategies](#caching-strategy) section for more information.\n\n### memoizeDecorator(options)\n\nReturns a [decorator](https://github.com/tc39/proposal-decorators) to memoize class methods, static class methods, or getters.\n\nNotes:\n\n- Uses [TC39 stage 3 decorators](https://github.com/tc39/proposal-decorators), supported natively in TypeScript 5.0+ and modern JavaScript engines;\n- Only class methods and getters can be memoized.\n\n#### options\n\nType: `object`\n\nSame as options for `memoize()`.\n\n```ts\nimport {memoizeDecorator} from 'memoize';\n\nclass Example {\n\tindex = 0\n\n\t@memoizeDecorator()\n\tcounter() {\n\t\treturn ++this.index;\n\t}\n}\n\nclass ExampleWithOptions {\n\tindex = 0\n\n\t@memoizeDecorator({maxAge: 1000})\n\tcounter() {\n\t\treturn ++this.index;\n\t}\n}\n\nclass ExampleWithGetter {\n\t@memoizeDecorator()\n\tget value() {\n\t\treturn expensiveComputation();\n\t}\n}\n```\n\n### memoizeClear(fn)\n\nClear all cached data of a memoized function.\n\n#### fn\n\nType: `Function`\n\nThe memoized function.\n\n### memoizeIsCached(fn, ...arguments)\n\nCheck if a specific set of arguments is cached for a memoized function.\n\nReturns `true` if the arguments are cached and not expired, `false` otherwise.\n\nUses the same argument processing as the memoized function, including any custom `cacheKey` function.\n\n```js\nimport memoize, {memoizeIsCached} from 'memoize';\n\nconst expensive = memoize((a, b) => a + b, {cacheKey: JSON.stringify});\nexpensive(1, 2);\n\nmemoizeIsCached(expensive, 1, 2);\n//=> true\n\nmemoizeIsCached(expensive, 3, 4);\n//=> false\n```\n\n#### fn\n\nType: `Function`\n\nThe memoized function.\n\n#### arguments\n\nThe arguments to check.\n\n## Tips\n\n### Cache statistics\n\nIf you want to know how many times your cache had a hit or a miss, you can make use of [stats-map](https://github.com/SamVerschueren/stats-map) as a replacement for the default cache.\n\n#### Example\n\n```js\nimport memoize from 'memoize';\nimport StatsMap from 'stats-map';\nimport got from 'got';\n\nconst cache = new StatsMap();\nconst memoizedGot = memoize(got, {cache});\n\nawait memoizedGot('https://sindresorhus.com');\nawait memoizedGot('https://sindresorhus.com');\nawait memoizedGot('https://sindresorhus.com');\n\nconsole.log(cache.stats);\n//=> {hits: 2, misses: 1}\n```\n\n## Related\n\n- [p-memoize](https://github.com/sindresorhus/p-memoize) - Memoize promise-returning & async functions\n","readmeFilename":"readme.md"}