{"_id":"memoization-registry","_rev":"2-6387007a941928ef3476c99730f9db65","name":"memoization-registry","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"memoization-registry","version":"1.0.0","keywords":["memoization","finalization","registry","memory","leak"],"_id":"memoization-registry@1.0.0","maintainers":[{"name":"fabiospampinato","email":"spampinabio@gmail.com"}],"homepage":"https://github.com/fabiospampinato/memoization-registry#readme","bugs":{"url":"https://github.com/fabiospampinato/memoization-registry/issues"},"dist":{"shasum":"3ea90a176a9681a0ee66c6e4df319fc914fc0faa","tarball":"https://registry.npmjs.org/memoization-registry/-/memoization-registry-1.0.0.tgz","fileCount":15,"integrity":"sha512-RTKJ11YUNtSL2EDkAEAAykywwaH2vfhh+oFk5oNwX3IHXwVkkaSDC++SAAvq2z8MbCaVLTVvIlmV3V/AzJzBSQ==","signatures":[{"sig":"MEYCIQCqPgeU7+yG3YT6K2qXtp0ILlzC/Zw5BREi3kE9ywkH/QIhAMoENDWZV5wolQQLx3sTRM2yVilPsTx/FhkAOawE6Bnb","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":15459,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj6vUnACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoxjA/8DimqtY6FBRh0JZs6FzKthMmDWWIV/Aunc6SlxZqmbRYSL9h/\r\nkYK1CdxVftfoKHzPq/45+bI4dUCgY0EpVBh1j59YmYpWJsKgvRnl4b6aojh5\r\n8DLvEwd59UAGL+yyy223cKKrAMkMy17CDAIQ99tcyK7TBxLUypkzdhC2v+tz\r\nNcf/fV+gNySV1Ja7yRw9R+TjKt9EIgtXw72lNBlbol9X65dHpXCq/CuX9ruV\r\nCKNBHdtBaJUukf1WPOG/P3v7/fU+AtfotcUjBzJHupJIbsIQNcj3UHt9jiK8\r\nZfBoQ+Uyw6fpX4aLZJIxGIcJ0mm6sl6Cjx5TzeSQfa1Y3ylO1Is9sRPn/Kuc\r\n9s1UNn80M3iG5xpEEjrUM4+Mzhq/8VSQeJmBk8SykPCPzRCaRe6WRPgaefk5\r\nHzTf/3W2c4x0rdSiItszE67I1zXV8kRLchYeT3olZeIOylsx/kLUh4yk//9K\r\nJdRicRI9t5x5pkHqKvhuDrszOhz6U0IGqAMRV7BAPrz4DoPcq34gCOcfKs5A\r\nYf8Jqec3rk37V5NFk/P20pNBw5elWof0yOK52elqaI8uhGpoNGOdWh3C7b3T\r\nA2D2DOmJ3EsAaE8qE3dmFs3HPwmnLTdjQQYmc5CeZPZkW0q1I7Dho2O1irmL\r\n/D7ZA6sp4RpyrYFYGtULzOXfeYOTEORe8Ek=\r\n=wAMR\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","exports":"./dist/index.js","scripts":{"test":"node --expose-gc test/index.js","clean":"tsex clean","compile":"tsex compile","compile:watch":"tsex compile --watch","prepublishOnly":"npm run clean && npm run compile && npm run test"},"_npmUser":{"name":"fabiospampinato","email":"spampinabio@gmail.com"},"repository":{"url":"git+https://github.com/fabiospampinato/memoization-registry.git","type":"git"},"_npmVersion":"8.19.2","description":"A generalized multi-key memoization solution that does not leak memory.","directories":{},"_nodeVersion":"18.12.0","dependencies":{"mild-map":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{"fava":"^0.1.2","tsex":"^2.1.0","typescript":"^4.9.5"},"_npmOperationalInternal":{"tmp":"tmp/memoization-registry_1.0.0_1676342567120_0.41584167249011394","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"memoization-registry","version":"1.0.1","keywords":["memoization","finalization","registry","memory","leak"],"_id":"memoization-registry@1.0.1","maintainers":[{"name":"fabiospampinato","email":"spampinabio@gmail.com"}],"homepage":"https://github.com/fabiospampinato/memoization-registry#readme","bugs":{"url":"https://github.com/fabiospampinato/memoization-registry/issues"},"dist":{"shasum":"e931e56c59f4e985f955d19e9314816f92af3df0","tarball":"https://registry.npmjs.org/memoization-registry/-/memoization-registry-1.0.1.tgz","fileCount":15,"integrity":"sha512-jKMBM586f/vsZVhmOO4mh1QH7Kx3BV/gIqxR3/hTh4L0Lej3P0POhPuC/dSuYQ6i3sSJwafvCFJic62rGzwtBw==","signatures":[{"sig":"MEYCIQD1Pg7r/pSDcpqKtqjHRSfa/VsVIUFrfBc2l38yoz6HjAIhAKMwfm6bth1V7Gti6lmG7t7fFoWa0fUEXw4tTU/faxWB","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":16068,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj663nACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp2LQ/9EQoY6sSbMk81Nm/PEkbBa6ap3vz4jA8nR2EIwLZnhG05ETr+\r\nMRLpWj7qAh2u1EHW4W6+fcFHf24Z8Cw+TGJoAFCshO+FrmPAHEWGPDugNIyR\r\nJl8Mr5gFUConQhP5HcX44BjbmMZpg50IbZCFue/hk+wJLzCFqYMHCeEMu8FT\r\nvuiOf5KkaucMvCeGvjIHRhDFVV4t4wZ4Ovx+ueR88uM0GJbzX9e0rkang99i\r\nzvZfs250SF2YtQPxub9Vr17XE8s/0vv2XVLOzF6kHDr38b++VkwSlahYGsnV\r\nAfID35Z+ditxVckfQhl0GydIpB4D4GC+iATQLTweVpkaM6Y97bOQdThj2YTc\r\nLKr8gAgr63uM+fY7J9LbQwr3AP3BNofjA5huuL5WtWGIrOORcE0isS7GG9QC\r\nNl4GorCt+oQUG5dsX5iULfgU5XMT0m+hSv5rwTiMenodtc2JKZSYuoDjhw9B\r\nOpPIkoKfdVloroqUN3PtcPtBWdEEi/yazEbgSuX6rroIuLbdx4d5NTLnkgmV\r\nebdTc82H21q/thR0HbBSDPRBDSbXWdXtdrbiJ/2eeHlmPLfktjXCbQoWkNpT\r\nxGy+ziqxbwg+f3fL1ZSftsBTIHLmOoRLBxNTkVyECGEq1cHMakMCPp/FtDJ1\r\nliTwbIgJ6qxtaeERQ89vOfM9v0veHfoBmv4=\r\n=Gixu\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","exports":"./dist/index.js","gitHead":"b3bac1437960b4511cbdbb8e24afcf61e45e13d5","scripts":{"test":"node --expose-gc test/index.js","clean":"tsex clean","compile":"tsex compile","compile:watch":"tsex compile --watch","prepublishOnly":"npm run clean && npm run compile && npm run test"},"_npmUser":{"name":"fabiospampinato","email":"spampinabio@gmail.com"},"repository":{"url":"git+https://github.com/fabiospampinato/memoization-registry.git","type":"git"},"_npmVersion":"8.19.2","description":"A generalized multi-key memoization solution that does not leak memory.","directories":{},"_nodeVersion":"18.12.0","dependencies":{"mild-map":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"fava":"^0.1.2","tsex":"^2.1.0","typescript":"^4.9.5"},"_npmOperationalInternal":{"tmp":"tmp/memoization-registry_1.0.1_1676389862832_0.27836894271875745","host":"s3://npm-registry-packages"}},"1.0.2":{"name":"memoization-registry","repository":{"type":"git","url":"git+https://github.com/fabiospampinato/memoization-registry.git"},"description":"A generalized multi-key memoization solution that does not leak memory.","license":"MIT","version":"1.0.2","type":"module","main":"dist/index.js","exports":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"clean":"tsex clean","compile":"tsex compile","compile:watch":"tsex compile --watch","test":"node --expose-gc test/index.js","prepublishOnly":"npm run clean && npm run compile && npm run test"},"keywords":["memoization","finalization","registry","memory","leak"],"dependencies":{"mild-map":"^1.1.2"},"devDependencies":{"fava":"^0.3.4","tsex":"^4.0.2","typescript":"^5.7.3"},"_id":"memoization-registry@1.0.2","gitHead":"eb2b34273093423921ba372a38482111dfcc06d5","bugs":{"url":"https://github.com/fabiospampinato/memoization-registry/issues"},"homepage":"https://github.com/fabiospampinato/memoization-registry#readme","_nodeVersion":"18.19.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-HLYn0FWqDFOeghQtuDhHySUtphPWYHo63GLSSapaN2n9vXI6/zry6lJ+AvV9ZC34/w6CbscRnLwvtL89tnDr5Q==","shasum":"de4efc55d784dd9a46e78216e949342cbd3c985d","tarball":"https://registry.npmjs.org/memoization-registry/-/memoization-registry-1.0.2.tgz","fileCount":9,"unpackedSize":9949,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDf6gIbMXemCqDCTADbJFfYjpVUMdWUDQmY37tqQRuxDwIhAN5C4YjupUZC9Y74uLbz1YiR1wTdYH/QWur4q4bNfaRu"}]},"_npmUser":{"name":"fabiospampinato","email":"spampinabio@gmail.com"},"directories":{},"maintainers":[{"name":"fabiospampinato","email":"spampinabio@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/memoization-registry_1.0.2_1737901849703_0.8188389380414716"},"_hasShrinkwrap":false}},"time":{"created":"2023-02-14T02:42:47.119Z","modified":"2025-01-26T14:30:50.058Z","1.0.0":"2023-02-14T02:42:47.331Z","1.0.1":"2023-02-14T15:51:03.013Z","1.0.2":"2025-01-26T14:30:49.899Z"},"bugs":{"url":"https://github.com/fabiospampinato/memoization-registry/issues"},"homepage":"https://github.com/fabiospampinato/memoization-registry#readme","keywords":["memoization","finalization","registry","memory","leak"],"repository":{"type":"git","url":"git+https://github.com/fabiospampinato/memoization-registry.git"},"description":"A generalized multi-key memoization solution that does not leak memory.","maintainers":[{"name":"fabiospampinato","email":"spampinabio@gmail.com"}],"readme":"# Memoization Registry\n\nA generalized multi-key memoization solution that does not leak memory.\n\n## Features\n\n- It supports memoizing on multiple arbitrary keys.\n- It supports memoizing things other than function calls too.\n- It doesn't hold strong references to memoized values nor memoization keys, unless they are primitives.\n\n## Install\n\n```sh\nnpm install memoization-registry\n```\n\n## Usage\n\nMaybe the best way to explain what this allows for is with an example, how would you write a \"Magic\" class in such a way that all the following assertions succeeded?\n\n```ts\nclass Foo extends Magic {}\n\nconst foo1 = new Foo ( 'some-id' );\nconst foo2 = new Foo ( 'other-id' );\nconst foo3 = new Foo ( 'some-id' );\n\nconsole.assert ( foo1 !== foo2 );\nconsole.assert ( foo2 !== foo3 );\nconsole.assert ( foo1 === foo3 );\n\nclass Bar extends Foo {}\n\nconst bar1 = new Bar ( 'some-id' );\nconst bar2 = new Bar ( 'other-id' );\nconst bar3 = new Bar ( 'some-id' );\n\nconsole.assert ( foo1 !== bar1 );\nconsole.assert ( foo2 !== bar2 );\nconsole.assert ( foo3 !== bar3 );\n\nconsole.assert ( bar1 !== bar2 );\nconsole.assert ( bar2 !== bar3 );\nconsole.assert ( bar1 === bar3 );\n```\n\nIt may seem borderline impossible to simply make that work without any problems -- basically we want to automatically memoize some class instances, but the thing to memoize is not a regular function call, and we don't want to hold strong references to the memoized values, nor the memoization keys, as that will cause a memory leak.\n\nHere's a solution, enabled by this powerful library:\n\n```ts\nimport MemoizationRegistry from 'memoization-registry';\n\nconst registry = new MemoizationRegistry<[Function, string], Magic> ();\n\nclass Magic {\n  constructor ( id: string ) {\n    const keys = [new.target, id];\n    const factory = () => this;\n    return registry.register ( keys, factory );\n  }\n}\n\nclass Foo extends Magic {}\n\nconst foo1 = new Foo ( 'some-id' );\nconst foo2 = new Foo ( 'other-id' );\nconst foo3 = new Foo ( 'some-id' );\n\nconsole.assert ( foo1 !== foo2 );\nconsole.assert ( foo2 !== foo3 );\nconsole.assert ( foo1 === foo3 );\n\nclass Bar extends Foo {}\n\nconst bar1 = new Bar ( 'some-id' );\nconst bar2 = new Bar ( 'other-id' );\nconst bar3 = new Bar ( 'some-id' );\n\nconsole.assert ( foo1 !== bar1 );\nconsole.assert ( foo2 !== bar2 );\nconsole.assert ( foo3 !== bar3 );\n\nconsole.assert ( bar1 !== bar2 );\nconsole.assert ( bar2 !== bar3 );\nconsole.assert ( bar1 === bar3 );\n```\n\n## License\n\nMIT © Fabio Spampinato\n","readmeFilename":"readme.md","license":"MIT"}