{"_id":"flru","_rev":"3329724","name":"flru","description":"A tiny (215B) and fast Least Recently Used (LRU) cache","dist-tags":{"latest":"1.0.2"},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"time":{"modified":"2024-07-10T07:12:07.000Z","created":"2018-12-24T05:55:08.320Z","1.0.2":"2019-07-11T19:26:24.951Z","1.0.1":"2019-05-31T18:25:42.416Z","1.0.0":"2019-01-08T21:34:32.017Z","0.0.0":"2018-12-24T05:55:08.320Z"},"users":{},"author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"lukeed.com"},"repository":{"type":"git","url":"git+https://github.com/lukeed/flru.git"},"versions":{"1.0.2":{"name":"flru","version":"1.0.2","repository":{"type":"git","url":"git+https://github.com/lukeed/flru.git"},"description":"A tiny (215B) and fast Least Recently Used (LRU) cache","unpkg":"dist/flru.min.js","module":"dist/flru.mjs","main":"dist/flru.js","types":"flru.d.ts","license":"MIT","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"lukeed.com"},"engines":{"node":">=6"},"scripts":{"build":"bundt","pretest":"npm run build","test":"tape test/*.js | tap-spec"},"keywords":["lru","cache","lru-cache","mru"],"devDependencies":{"bundt":"^0.4.0","tap-spec":"^5.0.0","tape":"^4.9.1"},"gitHead":"35d9a9aa9d29a6c6a2fb7948be04c1f6dddc3baf","bugs":{"url":"https://github.com/lukeed/flru/issues"},"homepage":"https://github.com/lukeed/flru#readme","_id":"flru@1.0.2","_npmVersion":"6.4.1","_nodeVersion":"10.13.0","_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"dist":{"shasum":"1ae514c62b8b035ffff9ca9e4563ddcc817f4845","size":3883,"noattachment":false,"key":"/flru/-/flru-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/flru/download/flru-1.0.2.tgz"},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/flru_1.0.2_1562873184820_0.6306513915915619"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-22T03:38:51.348Z","publish_time":1562873184951,"_cnpm_publish_time":1562873184951},"1.0.1":{"name":"flru","version":"1.0.1","repository":{"type":"git","url":"git+https://github.com/lukeed/flru.git"},"description":"A tiny (215B) and fast Least Recently Used (LRU) cache","unpkg":"dist/flru.min.js","module":"dist/flru.mjs","main":"dist/flru.js","types":"flru.d.ts","license":"MIT","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"lukeed.com"},"engines":{"node":">=6"},"scripts":{"build":"bundt","pretest":"npm run build","test":"tape test/*.js | tap-spec"},"keywords":["lru","cache","lru-cache","mru"],"devDependencies":{"bundt":"^0.4.0","tap-spec":"^5.0.0","tape":"^4.9.1"},"gitHead":"c83dcc832e8cbb6891a93dc134414a65257a20c2","bugs":{"url":"https://github.com/lukeed/flru/issues"},"homepage":"https://github.com/lukeed/flru#readme","_id":"flru@1.0.1","_npmVersion":"6.4.1","_nodeVersion":"10.13.0","_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"dist":{"shasum":"cb5625808422f3dfacee5d3ddf2fb66dc299383a","size":3869,"noattachment":false,"key":"/flru/-/flru-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/flru/download/flru-1.0.1.tgz"},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/flru_1.0.1_1559327142276_0.06442452271425037"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-22T03:38:50.484Z","publish_time":1559327142416,"_cnpm_publish_time":1559327142416},"1.0.0":{"name":"flru","version":"1.0.0","repository":{"type":"git","url":"git+https://github.com/lukeed/flru.git"},"description":"A tiny (215B) and fast Least Recently Used (LRU) cache","unpkg":"dist/flru.min.js","module":"dist/flru.mjs","main":"dist/flru.js","license":"MIT","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"lukeed.com"},"engines":{"node":">=6"},"scripts":{"build":"bundt","pretest":"npm run build","test":"tape test/*.js | tap-spec"},"keywords":["lru","cache","lru-cache","mru"],"devDependencies":{"bundt":"^0.1.1","tap-spec":"^5.0.0","tape":"^4.9.1"},"gitHead":"62e676933095e5ab64ddc15763a33982d6515b92","bugs":{"url":"https://github.com/lukeed/flru/issues"},"homepage":"https://github.com/lukeed/flru#readme","_id":"flru@1.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.12.0","_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"dist":{"shasum":"77c2a3c851359bba95df18c021c6e248b213fa56","size":3729,"noattachment":false,"key":"/flru/-/flru-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/flru/download/flru-1.0.0.tgz"},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/flru_1.0.0_1546983271893_0.9321812658329991"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-22T03:38:49.589Z","publish_time":1546983272017,"_cnpm_publish_time":1546983272017},"0.0.0":{"name":"flru","version":"0.0.0","repository":{"type":"git","url":"git+https://github.com/lukeed/flru.git"},"description":"WIP","unpkg":"dist/flru.min.js","module":"dist/flru.mjs","main":"dist/flru.js","license":"MIT","author":{"name":"Luke Edwards","email":"luke.edwards05@gmail.com","url":"lukeed.com"},"engines":{"node":">=6"},"scripts":{"build":"node builder","pretest":"npm run build","test":"tape test/*.js | tap-spec"},"keywords":[],"devDependencies":{"gzip-size":"^3.0.0","mk-dirs":"^1.0.0","pretty-bytes":"^4.0.2","tap-spec":"^5.0.0","tape":"^4.9.1","terser":"^3.10.0"},"gitHead":"244d117ba7609ad56ef35a1805d22f977a9ad247","bugs":{"url":"https://github.com/lukeed/flru/issues"},"homepage":"https://github.com/lukeed/flru#readme","_id":"flru@0.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.13.0","_npmUser":{"name":"lukeed","email":"luke@lukeed.com"},"dist":{"shasum":"8960e7538a43bc213994da5e6583a361d67e9b16","size":2128,"noattachment":false,"key":"/flru/-/flru-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/flru/download/flru-0.0.0.tgz"},"maintainers":[{"name":"lukeed","email":"luke@lukeed.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/flru_0.0.0_1545630908223_0.36250627776823974"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2021-12-22T03:38:48.730Z","publish_time":1545630908320,"_cnpm_publish_time":1545630908320}},"readme":"# flru [![Build Status](https://travis-ci.org/lukeed/flru.svg?branch=master)](https://travis-ci.org/lukeed/flru)\n\n> A tiny (215B) and fast Least Recently Used (LRU) cache\n\nInternally, two caches are kept. This is because it's far more performant to swap (and maintain) dictionaries than it is to `delete`/purge keys on every read/write interaction. Because of this, `flru` will store `2n` items in memory, where `n` is the [`max`](#max) limit. In practice, this means that with `max=3` and items `(a, b, c)` already written, writing a `d` value ***will not*** automatically purge the `a` key. Instead, `a` _can_ be retrieved, which would move it to the \"active\" cache. It's only when this \"active\" half exceeds the `max` that the \"stale\" half is purged.\n\n> See [Usage](#Usage) for a visual explanation~!\n\nThis implementation is optimized for all-around performance – reads, writes, updates, and evictions.\n\n\nThis module is available in three formats:\n\n* **ES Module**: `dist/flru.mjs`\n* **CommonJS**: `dist/flru.js`\n* **UMD**: `dist/flru.min.js`\n\n\n## Install\n\n```\n$ npm install --save flru\n```\n\n\n## Usage\n\n```js\n// Legend:\n//    S => the stale cache\n//    A => the active cache\n\nconst flru = require('flru');\n\nlet cache = flru(3); // A=[]        S=[]\n\ncache.set('a', 1);   // A=[a]       S=[]\ncache.set('b', 2);   // A=[a,b]     S=[]\ncache.set('b', 9);   // A=[a,b]     S=[]\ncache.set('c', 3);   // A=[a,b,c]   S=[]\n\ncache.has('a'); //=> true\n\ncache.set('d', 4);   // A=[d]       S=[a,b,c]\ncache.get('a');      // A=[d,a]     S=[a,b,c]\ncache.set('e', 5);   // A=[d,a,e]   S=[a,b,c]\ncache.get('a');      // A=[d,a,e]   S=[a,b,c]\ncache.get('c');      // A=[c]       S=[d,a,e]\n\ncache.has('c'); //=> true\ncache.has('b'); //=> false\ncache.has('a'); //=> true\n\ncache.clear();       // A=[]      S=[]\n```\n\n\n## API\n\n### flru(max)\nreturn `Object`\n\nInitialize a new `flru` cache instance.\n\n#### max\nRequired: `true`<br>\nType: `Number`<br>\nDefault: `1`\n\nThe maximum number of items to maintain – must be a positive, non-zero integer!\n\n> **Important:** The default value is pointless and will result in excessive computation. It's there only to avoid memory leak!\n\n\n### flru.has(key)\nReturn: `Boolean`\n\nCheck if the cache has the given key.\n\n#### key\nType: `String`\n\nThe key name to check.\n\n\n### flru.get(key)\nReturn: `Mixed`\n\nGet the assigned value for a given key. Will return `undefined` if the cache has evicted `key` or never contained it.\n\n#### key\nType: `String`\n\nThe item's unique name / identifier.\n\n\n### flru.set(key, value)\nReturn: `undefined`\n\nPersist an item to the cache by a given `key` name.\n\n#### key\nType: `String`\n\nThe item's unique name / identifier.\n\n#### value\nType: `Mixed`\n\nThe item's value to be cached.\n\n\n### flru.clear(keepOld)\nReturn: `undefined`\n\nReset the cache(s) and counter.\n\n#### keepOld\nType: `Boolean`<br>\nDefault: `false`\n\nWhen `true`, preserves the stale/outgoing cache.\n\n> **Important:** This is used internally & generally should be ignored!\n\n\n## Benchmarks\n\nYou can find benchmarks in the [`bench`]() directory. They are setup to run one library at a time so that there's no cross-contamination of memory management or Node's runtime caching.\n\n* `set` – writing values into _new_ keys\n* `update` – updating values into _existing_ keys\n* `evict` – writing `2 * limit` keys to the cache, forcing eviction\n\n> Results below are with Node v10.13.0\n\n```\n# set()\nflru       x 45,261 ops/sec ±1.63% (94 runs sampled)\nlru-cache  x 14,240 ops/sec ±5.70% (85 runs sampled)\ntmp-cache  x  8,229 ops/sec ±3.06% (83 runs sampled)\ntiny-lru   x 24,415 ops/sec ±2.48% (91 runs sampled)\n\n# get()\nflru       x 78,585 ops/sec ±1.70% (98 runs sampled)\nlru-cache  x 27,409 ops/sec ±2.64% (93 runs sampled)\ntmp-cache  x  6,229 ops/sec ±1.06% (87 runs sampled)\ntiny-lru   x 20,313 ops/sec ±2.01% (96 runs sampled)\n\n# has()\nflru       x  79,843 ops/sec ±1.35% (97 runs sampled)\nlru-cache  x  31,354 ops/sec ±2.87% (90 runs sampled)\ntmp-cache  x 813,828 ops/sec ±64.67% (95 runs sampled)\ntiny-lru   x 128,250 ops/sec ±3.73% (93 runs sampled)\n\n# update()\nflru       x 44,885 ops/sec ±1.86% (95 runs sampled)\nlru-cache  x 15,616 ops/sec ±2.46% (94 runs sampled)\ntmp-cache  x  8,529 ops/sec ±0.85% (87 runs sampled)\ntiny-lru   x 23,060 ops/sec ±2.72% (93 runs sampled)\n\n# evict()\nflru       x 8,258 ops/sec ±1.48% (88 runs sampled)\nlru-cache  x 1,492 ops/sec ±2.60% (77 runs sampled)\ntmp-cache  x   836 ops/sec ±0.59% (95 runs sampled)\ntiny-lru   x 2,626 ops/sec ±2.61% (81 runs sampled)\n```\n\n\n## Related\n\n- [tmp-cache](https://github.com/lukeed/tmp-cache) - Full-featured (but slower) alternative, supporting time-sensitive expirations.\n- [`tiny-lru`](https://github.com/avoidwork/tiny-lru) - Same as `tmp-cache` but significantly faster.\n\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","_attachments":{},"homepage":"https://github.com/lukeed/flru#readme","bugs":{"url":"https://github.com/lukeed/flru/issues"},"license":"MIT"}