{"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":{"integrity":"sha512-FbvciQ1XmT83gulnqgSP/AVC1Jqi/xrwHHdBwyIajp5+TWMwjdGtkUR8FDCd+opNi9mNmdw6i8xFxlZn6yI95g==","shasum":"cb5625808422f3dfacee5d3ddf2fb66dc299383a","tarball":"http://registry-npm.ywwl.com/flru/download/flru-1.0.1.tgz","fileCount":7,"unpackedSize":8911,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc8XGmCRA9TVsSAnZWagAAH1YP/AhrPnRVCALo5i4F7z5H\ndys/TiVLQf7D1Nx3x1IhwFRxtkovScpQUt56Qzv1BBkixHSKdu7rbNpGTS4g\nlWPo85v9BfNH3Uf08ZMNZi2F9gdXhf272NSOvGHm1wzvVEny1TrNzfRc+cbl\nmcpOiWJk+yzKpX4pQzfH9DiE3Ivx3FlNxiNgkZujPxLUhOh/1EDFchdH8D3t\nGg2BmcamIzT0tbMHEYl8CFl98GXG0WPO1aNKy5y/SSv4kSOryF0P7vbtjwVC\nUVb6oXMvTy2o5av3TTsXlKbasgZbgdTM6qmClA7Js/8vZFsQKUPuPK+WtshO\n1jVGQaOFMU9gO4H0r1Ul0rp7PcOEDubl2JftqaEs9wdBNqBeV/itopEwIMWz\nwB2AgAc+Y8RlepM0YDulFIuwBp/O5E/OoRIilNnh0FVvDofsInYIWuNk7Q59\n0FXc3uUBVI1sccmdSgC39TnXCjPslZAk8BUBMJ8OEPhU3m4ZMZV3an4e3IPU\nYHuOshcNHjdyhdeomgJFX9vPRCUcZiS7Au/yXznzrivAPN9g48AeL9tS52Sh\nYe4X7zy5K1/2RQYthpFuZliJiZY9jqC1Yo/PRZxg2EsJAKOTBw9LtbK6t1WZ\nzCAs1hG+FuiQcVMNRej0N9dRPy+ibY4L5h1uM+scwTF7RjCLgwoT105u1jrf\nEu7+\r\n=2hnC\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH02/xysQQXKPBmJnThw/fXk8/1LpQjK9ajGnXOX22uPAiEA3Z0rHMJL2XM/7w/5FaLU8pGgxszlrm2N2tCYWd/gKGA="}],"size":3869,"noattachment":false,"key":"/flru/-/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,"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":1559327142416,"_cnpm_publish_time":1559327142416,"dist-tags":{"latest":"1.0.2"}}