{"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":{"integrity":"sha512-kWyh8ADvHBFz6ua5xYOPnUroZTT/bwWfrCeL0Wj1dzG4/YOmOcfJ99W8dOVyyynJN35rZ9aCOtHChqQovV7yog==","shasum":"1ae514c62b8b035ffff9ca9e4563ddcc817f4845","tarball":"http://registry-npm.ywwl.com/flru/download/flru-1.0.2.tgz","fileCount":7,"unpackedSize":8940,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdJ41hCRA9TVsSAnZWagAAzR8P/iPt10nuRngCk6b0KXBx\nyOTHeDkykSWbd2Lvx9P3gKp1roZqRyM0hBGBC9ij9dPDrI2n2Y+GRv1lT3ND\n8szVsoB7+fYUXBppW5L5xm1VDUDIesiWlAdpy6G7IstyXHHfghh9/HiFdl3e\naXrMxMH+kxOyRgAQxLYVuVmGyfgR8bofx82X+LSnwUmV0ra89ZBfV0AdNcmk\ntKDK0qNgaF+FwgQDSZBzCB3D/W5trz+G1y0Y1L1ZwI/wl56LKw+tPuSavKR+\nF5OwAcpe2y3iagurDUQuE0Ian2e10DpHHsFV+WpkuRUkZNkcXymocpBFri5B\nCImQsjtJO1VnUgQ9oGcFIsEArvLXw3jds7g6Tl6i+vk4gPyVdJX6CCOMYZ5U\nwjKKFFMr2uCviCZPZRf9w6RUIlThEKJ3qlzrzcyHUqcUlqU7dfwWbqoZObiL\nDNkiLJVdMkJJN3RD6OKvo//28B6D+TwmCiAS+LUq2ee1jLXP2PfsGUXAq55y\ni8wH6FTYg8Ei24luRrd0uZqR+yHKPcXlghCnCpMGJ/B35y+GOVcoIwiTYW0r\n5x7yNDXpptVs6LzGqZKyBLynNGUeA/XVLf7eIprc39pnv1vphE1lmSUzFtIR\nXIwxDT4vJWAl+dO130d3lt58/Au9yKehTFuUAW5pXwHcf304tmqVtHPSz/IR\n3scP\r\n=a6dV\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDV/xgdCItYaXSsl8779jTgiQO1S+HY1q//Sg//JG0S6wIgCPqi28CyQXi7zN/JCTAptf3Xrn+TxyGx3gUrT5nt3MQ="}],"size":3883,"noattachment":false,"key":"/flru/-/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,"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","publish_time":1562873184951,"_cnpm_publish_time":1562873184951,"dist-tags":{"latest":"1.0.2"}}