{"_id":"rache@1.0.1","bugs":{"url":"https://github.com/holepunchto/rache/issues"},"dist":{"shasum":"8ec986379cbe066fbe61cf091c9ad0f30c09b379","tarball":"http://registry-npm.ywwl.com/rache/download/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,"size":6175,"noattachment":false,"key":"/rache/-/rache-1.0.1.tgz"},"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"},"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","publish_time":1793078457470,"_cnpm_publish_time":1793078457470,"dist-tags":{"latest":"1.0.1"}}