{"_id":"rache","_rev":"8-0142b142af8ffa9e15175cba60a118f0","name":"rache","dist-tags":{"latest":"1.0.1"},"versions":{"0.0.0":{"name":"rache","version":"0.0.0","author":"","license":"Apache-2.0","_id":"rache@0.0.0","dist":{"shasum":"737a5f0e1752b59b9f07636be6bb7ee17e02f4f0","tarball":"https://registry.npmjs.org/rache/-/rache-0.0.0.tgz","fileCount":1,"integrity":"sha512-rS6VfNU/LYK6XrRzEjvBmUm3qTerQJooERsz4h3DENJUpQ+GzfCD5kVDSqsOT+H/zsyWcxCiamHMVZ9k7aam3A==","signatures":[{"sig":"MEYCIQCAnFKWgiCfjzDsvcZRZzA1YfrCL35vsqxmCMtYGHJz3AIhALHGLF5WkXMHNysXQKqETRe2uy2DR/FKVRCO1nz6vg67","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":229},"main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"_npmVersion":"10.7.0","description":"Random-eviction cache","directories":{},"_nodeVersion":"20.11.1","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/rache_0.0.0_1719931117799_0.6964390999254779","host":"s3://npm-registry-packages"}},"0.0.1":{"name":"rache","version":"0.0.1","author":{"name":"Holepunch"},"license":"Apache-2.0","_id":"rache@0.0.1","maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"},{"name":"hdegroote","email":"hans_npm@mailbox.org"}],"homepage":"https://github.com/holepunchto/rache#readme","bugs":{"url":"https://github.com/holepunchto/rache/issues"},"dist":{"shasum":"e747fad1c209541cee5bb24dda3699bce1ea8c9f","tarball":"https://registry.npmjs.org/rache/-/rache-0.0.1.tgz","fileCount":4,"integrity":"sha512-As5vkqsd6oESgunQm3BS461lcRxzRUB33o52PuE+5GDdsebjxGhtkgOYz/VWdQ899UtH18UvNnk8aIAfukcdIg==","signatures":[{"sig":"MEUCIA5/b7nMenD71mKMXJMb31+KV+SD93ig40WtY0y8DY/wAiEA3zDEhqx/FpJZO8A9jjnc87PuTvab4ehxe26cAulCmJc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":16404},"main":"index.js","gitHead":"576ebcae53058c3bfc74c474eb2f997cdb797809","scripts":{"test":"standard && brittle test.js --coverage"},"_npmUser":{"name":"hdegroote","email":"hans_npm@mailbox.org"},"repository":{"url":"git+https://github.com/holepunchto/rache.git","type":"git"},"_npmVersion":"9.3.0","description":"Random-eviction cache","directories":{},"_nodeVersion":"18.12.1","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"brittle":"^3.5.2","standard":"^17.1.0"},"_npmOperationalInternal":{"tmp":"tmp/rache_0.0.1_1719952952662_0.3304903909678991","host":"s3://npm-registry-packages"}},"0.0.2":{"name":"rache","version":"0.0.2","author":{"name":"Holepunch"},"license":"Apache-2.0","_id":"rache@0.0.2","maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"},{"name":"hdegroote","email":"hans_npm@mailbox.org"}],"homepage":"https://github.com/holepunchto/rache#readme","bugs":{"url":"https://github.com/holepunchto/rache/issues"},"dist":{"shasum":"edf23524ab476bf49b04a712788b4bd1367a08c6","tarball":"https://registry.npmjs.org/rache/-/rache-0.0.2.tgz","fileCount":4,"integrity":"sha512-Zqz3dfZVkd9BSYe2di703a/D9Kzvh9Dv69q6SURSzT/8+vwi9a0Z/NGzGiaKxQE+2NjcBRweeB70V43pz4roRQ==","signatures":[{"sig":"MEUCIQDopr0umAU83puICKBTTRol1X3B80d1NRQU8eSID0C9xwIgOOu1L0E+EViiPobRHmc7xVkVx+TQ45hZKCTXpHYA6Q8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":16563},"main":"index.js","gitHead":"bfdf057d26665dc2cedf78106ec04dbc2f56cf7c","scripts":{"test":"standard && brittle test.js --coverage"},"_npmUser":{"name":"hdegroote","email":"hans_npm@mailbox.org"},"repository":{"url":"git+https://github.com/holepunchto/rache.git","type":"git"},"_npmVersion":"9.3.0","description":"Random-eviction cache","directories":{},"_nodeVersion":"18.12.1","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"brittle":"^3.5.2","standard":"^17.1.0"},"_npmOperationalInternal":{"tmp":"tmp/rache_0.0.2_1719997246188_0.970875714346213","host":"s3://npm-registry-packages"}},"0.0.3":{"name":"rache","version":"0.0.3","author":{"name":"Holepunch"},"license":"Apache-2.0","_id":"rache@0.0.3","maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"},{"name":"hdegroote","email":"hans_npm@mailbox.org"}],"homepage":"https://github.com/holepunchto/rache#readme","bugs":{"url":"https://github.com/holepunchto/rache/issues"},"dist":{"shasum":"301f646202595c1f8440fbfd95b484776f97fdda","tarball":"https://registry.npmjs.org/rache/-/rache-0.0.3.tgz","fileCount":4,"integrity":"sha512-QxLfsUZK4e1BoMZ6GfxBxLrpeTBcZHPK5oUb1aPPozAJyJxx5BNT3p/ANgPcHnZZZebX+hnPLTgEEMmQOwgP9w==","signatures":[{"sig":"MEUCIQDpP94mbqkGO/1lpegXJa9KMYNOVc4ocLsJT0nrMJqMEgIgUtoCxKkbkRD55ypQ9b5a9ZUnujWhasFusiky16gV6t0=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":16935},"main":"index.js","gitHead":"62d4ccbdd9d83a39b0e7cc300edd17c37c9dd49c","scripts":{"test":"standard && brittle test.js --coverage"},"_npmUser":{"name":"hdegroote","email":"hans_npm@mailbox.org"},"repository":{"url":"git+https://github.com/holepunchto/rache.git","type":"git"},"_npmVersion":"9.3.0","description":"Random-eviction cache","directories":{},"_nodeVersion":"18.12.1","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"brittle":"^3.5.2","standard":"^17.1.0"},"_npmOperationalInternal":{"tmp":"tmp/rache_0.0.3_1720023592274_0.2483442570229326","host":"s3://npm-registry-packages"}},"1.0.0":{"name":"rache","version":"1.0.0","author":{"name":"Holepunch"},"license":"Apache-2.0","_id":"rache@1.0.0","maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"},{"name":"hdegroote","email":"hans_npm@mailbox.org"}],"homepage":"https://github.com/holepunchto/rache#readme","bugs":{"url":"https://github.com/holepunchto/rache/issues"},"dist":{"shasum":"e56f95abc0c056d3b86c9fdad6a004ce87921e30","tarball":"https://registry.npmjs.org/rache/-/rache-1.0.0.tgz","fileCount":4,"integrity":"sha512-e0k0g0w/8jOCB+7YqCIlOa+OJ38k0wrYS4x18pMSmqOvLKoyhmMhmQyCcvfY6VaP8D75cqkEnlakXs+RYYLqNg==","signatures":[{"sig":"MEYCIQCvt0wAhe3JwIJEslYbCOi1AEiVT4E3/665kW6eDgwvKAIhAO7ob6Mge2MVsPgYuDqp++pnhn6pBVDsIDCI33LTgOCf","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":17032},"main":"index.js","gitHead":"f657cbeb55599f3f197ec2441874e67bed94b2b6","scripts":{"test":"standard && brittle test.js --coverage"},"_npmUser":{"name":"hdegroote","email":"hans_npm@mailbox.org"},"repository":{"url":"git+https://github.com/holepunchto/rache.git","type":"git"},"_npmVersion":"9.3.0","description":"Random-eviction cache","directories":{},"_nodeVersion":"18.12.1","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"brittle":"^3.5.2","standard":"^17.1.0"},"_npmOperationalInternal":{"tmp":"tmp/rache_1.0.0_1720117883639_0.2522593063309564","host":"s3://npm-registry-packages"}},"1.0.1":{"_id":"rache@1.0.1","bugs":{"url":"https://github.com/holepunchto/rache/issues"},"dist":{"shasum":"8ec986379cbe066fbe61cf091c9ad0f30c09b379","tarball":"https://registry.npmjs.org/rache/-/rache-1.0.1.tgz","fileCount":4,"integrity":"sha512-c7dgBVFzM2wkbmFXafjMDC9TulltOTphcPxk4Q90h1lj2A2vBAnmF7p/L89zJ7/8we6f1SMunpSFHBwpTE9X0w==","signatures":[{"sig":"MEQCIEDHaNKXJLNRhesRpybzGu9OWXRmttbWFXVskZBGClqAAiBsaFGVzBFjS9B+mGZC8adR2z7L0Qg2O44rAZQ/ddRCbA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCaGbsQ8Jd8imvB8/FYa0r3vkhfoAAL0JoNkGpQvpxHlgIga/PaqRtIE7zC33zjegUa3vT/yEMcjEwF08aApX3hT5M="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/rache@1.0.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":17235},"main":"index.js","name":"rache","author":{"name":"Holepunch"},"gitHead":"d971a7bff6361beea0614d65c45ae3a73f262aa1","license":"Apache-2.0","scripts":{"lint":"prettier --check . && lunte","test":"npm run test:node && npm run test:bare","format":"prettier --write .","test:bare":"brittle-bare test.js","test:node":"brittle-node test.js --coverage"},"version":"1.0.1","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"a3cc1cc5-d8a4-49a7-82b1-6df37cdef363"}},"homepage":"https://github.com/holepunchto/rache#readme","repository":{"url":"git+https://github.com/holepunchto/rache.git","type":"git"},"_npmVersion":"11.19.1","description":"Random-eviction cache","directories":{},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"_nodeVersion":"24.22.1","_hasShrinkwrap":false,"devDependencies":{"lunte":"^1.0.0","brittle":"^3.5.2","prettier":"^3.6.2","prettier-config-holepunch":"^2.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/rache_1.0.1_1793078457382_0.5400218138692773"}}},"time":{"created":"2024-07-02T14:38:37.798Z","modified":"2026-10-27T05:20:57.862Z","0.0.0":"2024-07-02T14:38:37.965Z","0.0.1":"2024-07-02T20:42:32.812Z","0.0.2":"2024-07-03T09:00:46.337Z","0.0.3":"2024-07-03T16:19:52.404Z","1.0.0":"2024-07-04T18:31:23.783Z","1.0.1":"2026-10-27T05:20:57.470Z"},"bugs":{"url":"https://github.com/holepunchto/rache/issues"},"author":{"name":"Holepunch"},"license":"Apache-2.0","homepage":"https://github.com/holepunchto/rache#readme","repository":{"url":"git+https://github.com/holepunchto/rache.git","type":"git"},"description":"Random-eviction cache","maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"readme":"# Rache\n\nA random-eviction cache which imposes a global cache-size limit on all the caches derived from it.\n\nUseful when you have many caches and want to limit their memory usage as a whole, instead of per cache.\n\nThe `get` and `set` operations as well as `delete` (and cache eviction) take constant time.\n\n## Install\n\n```\nnpm i rache\n```\n\n## Usage\n\n```\nconst Rache = require('rache')\n\nconst cache = new Rache({ maxSize: 3 })\nconst cache2 = cache.sub()\nconst cache3 = cache.sub()\n\ncache.set('key', 'value')\ncache2.set('key', 'otherValue')\ncache3.set('some', 'thing')\n\n// cache 1 is a separate cache from cache2 and cache3\nconsole.log('cached:', cache.get('key')) // 'value'\n\n// But they share the same global size\nconsole.log(cache.globalSize, 'of', cache.maxSize) // 3 of 3\n\ncache.set('key2', 'another value')\n// The cache was full, so one of the existing 3 entries got evicted\n\nconsole.log(cache.globalSize, 'of', cache.maxSize) // 3 of 3\n```\n\n## API\n\n#### `const cache = new Rache({ maxSize=65536 })`\n\nCreate a new cache.\n\n`maxSize` is the maximum amount of entries globally, across this cache and all derived caches (derived with `cache.sub()` or `Rache.from(cache)`).\n\n#### `const subCache = cache.sub()`\n\nCreate a new cache which shares the global memory limit with the original cache.\n\n#### `const aCache = Rache.from(cache?)`\n\nCreate a new rache instance.\n\nIf an existing cache is passed in, it will create a sub-cache (equivalent to `aCache = cache.sub()`).\n\nOtherwise (if no `cache` or a falsy value is passed in), it will create a new cache (equivalent to `aCache = new Rache()`).\n\n#### `cache.globalSize`\n\nThe current amount of entries across all caches.\n\n#### `cache.maxSize`\n\nThe maximum amount of entries across all caches.\n\n#### `cache.size`\n\nThe amount of entries in this specific cache.\n\n#### `cache.set(key, value)`\n\nSet the key to the given value.\n\nIf the global cache size was at the limit, a random old entry is evicted from the cache.\n\n#### `cache.delete(key)`\n\nDelete the entry corresponding to `key`, if any.\n\nReturns `true` if an entry was deleted, `false` otherwise.\n\n#### `cache.get(key)`\n\nReturns the value corresponding to the given key, or `undefined` if there is none.\n\n#### `cache.keys()`\n\nReturns an iterator over the keys of this particular cache.\n\n#### `cache.values()`\n\nReturns an iterator over the values of this particular cache.\n\n#### `cache.clear()`\n\nClear all entries from this particular cache.\n\nAfter clearing, new entries can again be added to the cache.\n\n#### `cache.destroy()`\n\nDestroys the cache. The cache should no longer be used after it has been destroyed.\n","readmeFilename":"README.md"}