{"name":"record-cache","version":"2.0.0","description":"Cache optimised for record like things","main":"index.js","dependencies":{"b4a":"^1.3.1"},"devDependencies":{"brittle":"^3.19.1","lunte":"^1.4.0","prettier":"^3.6.2","prettier-config-holepunch":"^2.0.0"},"scripts":{"format":"prettier . --write","test":"prettier . --check && lunte && brittle test.js","lint":"lunte"},"repository":{"type":"git","url":"git+https://github.com/mafintosh/record-cache.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"MIT","bugs":{"url":"https://github.com/mafintosh/record-cache/issues"},"homepage":"https://github.com/mafintosh/record-cache","_id":"record-cache@2.0.0","gitHead":"478c5385c0c0390f379ddbb00ea47163585582f4","_nodeVersion":"22.16.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-xOQG4BL/sqDhGAaM7J7TQ8r68aetLElKyAeeWrOQc1GSbzFwW8nRbNuL264tT4V3UnOIroPecJsqtjisutat/g==","shasum":"67db0bc6b55b7dd2894644a1434dbe9be8407ed8","tarball":"http://registry-npm.ywwl.com/record-cache/download/record-cache-2.0.0.tgz","fileCount":9,"unpackedSize":12357,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIB8gtORW++7Ta9fORebMqRQuGdMWE5DEYaOyDsh4utsnAiEAqycup52Qj0TQX8l34zoXQ0BxVDnC7XiKNxpCSLleIpE="}],"size":4193,"noattachment":false,"key":"/record-cache/-/record-cache-2.0.0.tgz"},"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"directories":{},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/record-cache_2.0.0_1767280239126_0.8859774725523379"},"_hasShrinkwrap":false,"readme":"# record-cache\n\nCache optimised for record like things like `host:port` or `domain.names`.\n\n```\nnpm install record-cache\n```\n\n[![build status](https://travis-ci.org/mafintosh/record-cache.svg?branch=master)](https://travis-ci.org/mafintosh/record-cache)\n\n## Usage\n\n```js\nvar RecordCache = require('record-cache')\n\nvar cache = new RecordCache({\n  maxSize: 1000 // store ~1000 values at max\n  maxAge: 1000 // gc values older than ~1000ms\n})\n\ncache.add('hello', '127.0.0.1')\ncache.add('hello', '127.0.1.1')\ncache.add('hello', '127.0.0.2')\n\nconsole.log(cache.get('hello', 2)) // prints two of the above\n\n// wait 2s\nsetTimeout(function () {\n  console.log(cache.get('hello', 2)) // prints []\n}, 2000)\n```\n\n## API\n\n#### `var cache = new RecordCache([options])`\n\nCreate a new record cache.\n\nOptions include:\n\n```js\n{\n  maxSize: 1000, // approximate max size\n  maxAge: 1000, // approximate max age in ms\n  onStale: false // function called when evicting stale records\n}\n```\n\nIn the worst case the cache will be `2 * maxSize` large, and\nif `maxAge` is used old values are gc'ed every `0.66 * maxAge - 1.33 * maxAge` with an optional callback to the `onStale` function upon record eviction.\n\nThis is to greatly simplify the data structures and also gives us a pretty decent\nperf boost compared to other cache modules out there.\n\n#### `cache.add(recordName, value)`\n\nPush a new value to the record set. `value` should be serialisable.\n\n#### `cache.remove(recordName, value)`\n\nRemove a value from the record set. `value` should be a previously added value.\n\n#### `var list = cache.get(recordName, [maxCount])`\n\nGet a list of values from the record set. The list will be randomised.\nSpecify `maxCount` to only get this many values at max.\n\n#### `cache.size`\n\nGet the actual size of the cache.\n\n#### `cache.clear()`\n\nClear all values from the cache.\n\n#### `cache.destroy()`\n\nCompletely destroy the cache. Needed if you are using the `maxAge` option to\ncancel the gc timer.\n\n## License\n\nMIT\n","publish_time":1767280239256,"_cnpm_publish_time":1767280239256,"dist-tags":{"latest":"2.0.0"}}