{"_id":"lru-fast","_rev":"9-e254d6c01f8708b9b76b42489a93c4bf","name":"lru-fast","description":"finite key-value cache using the Least Recently Used (LRU) algorithm where the most recently used objects are keept in cache while less recently used items are purged","dist-tags":{"latest":"0.2.2"},"versions":{"0.1.0":{"name":"lru-fast","version":"0.1.0","description":"finite key-value cache using the Least Recently Used (LRU) algorithm where the most recently used objects are keept in cache while less recently used items are purged","main":"lru.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/rsms/js-lru.git"},"keywords":["cache","lru","buffer"],"author":{"name":"Rasmus Andersson","email":"me@rsms.me"},"license":"MIT","bugs":{"url":"https://github.com/rsms/js-lru/issues"},"homepage":"https://github.com/rsms/js-lru#readme","gitHead":"ff07a5078ff6b05398ce6434a84dc9a33fde537f","_id":"lru-fast@0.1.0","_shasum":"bef6601a6882bcfafcbaf05857add8ba5b5bfd49","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.4.0","_npmUser":{"name":"rsms","email":"rasmus@notion.se"},"dist":{"shasum":"bef6601a6882bcfafcbaf05857add8ba5b5bfd49","tarball":"https://registry.npmjs.org/lru-fast/-/lru-fast-0.1.0.tgz","integrity":"sha512-i+UzxuehLI6E/S1vilcfOphC5DAhi4VeqeJQf4Wbek+4HmvCJV7a0EpnpFjwbNPqWr8WL6UvVP83H9XKBj6rbA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAC8tVBzO7/Bt+jsK2Z8Tma5QY6n2MmZHzPzwzG1msatAiBraS8SUOwWO6WMcF3HQCXhkhJyIzWm07P3Y59oDODV0g=="}]},"maintainers":[{"name":"rsms","email":"rasmus@notion.se"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/lru-fast-0.1.0.tgz_1474299152155_0.1482094193343073"}},"0.1.1":{"name":"lru-fast","version":"0.1.1","description":"finite key-value cache using the Least Recently Used (LRU) algorithm where the most recently used objects are keept in cache while less recently used items are purged","main":"lru.js","typings":"lru.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/rsms/js-lru.git"},"keywords":["cache","lru","buffer"],"author":{"name":"Rasmus Andersson","email":"me@rsms.me"},"license":"MIT","bugs":{"url":"https://github.com/rsms/js-lru/issues"},"homepage":"https://github.com/rsms/js-lru#readme","gitHead":"aa530e39b362b9e7639d0978f4e3e6d687a6fbe6","_id":"lru-fast@0.1.1","_shasum":"4bc89e3d68423ec134de6dcd98297c084eb9da7e","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.4.0","_npmUser":{"name":"rsms","email":"rasmus@notion.se"},"dist":{"shasum":"4bc89e3d68423ec134de6dcd98297c084eb9da7e","tarball":"https://registry.npmjs.org/lru-fast/-/lru-fast-0.1.1.tgz","integrity":"sha512-5hjxN7HLFiq61LCvQaeYDIGfTcGREcdrAhORDLzsrlKZuR07TfVX2pKjN8ZUHjfT99jQdOyc7eD6BAB7BqOfDg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDoa6324mFVni9olcrCAgxEM8/cUT5kZnTLplE2luZIGAiBNQo2ekbnd23pkrx/o4FgtwiZBj5hCYOTfjgz+zX5rpQ=="}]},"maintainers":[{"name":"rsms","email":"rasmus@notion.se"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/lru-fast-0.1.1.tgz_1479140502926_0.23217585938982666"}},"0.1.2":{"name":"lru-fast","version":"0.1.2","description":"finite key-value cache using the Least Recently Used (LRU) algorithm where the most recently used objects are keept in cache while less recently used items are purged","main":"lru.js","typings":"lru.d.ts","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/rsms/js-lru.git"},"keywords":["cache","lru","buffer"],"author":{"name":"Rasmus Andersson","email":"me@rsms.me"},"license":"MIT","bugs":{"url":"https://github.com/rsms/js-lru/issues"},"homepage":"https://github.com/rsms/js-lru#readme","gitHead":"e8d1c19a7fedaf9b8d8bdac048dc2931c51aad4a","_id":"lru-fast@0.1.2","_shasum":"4aa38c061c31141ec0e6b32bc422cc86eb962894","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.4.0","_npmUser":{"name":"rsms","email":"rasmus@notion.se"},"dist":{"shasum":"4aa38c061c31141ec0e6b32bc422cc86eb962894","tarball":"https://registry.npmjs.org/lru-fast/-/lru-fast-0.1.2.tgz","integrity":"sha512-5Nisb1RSfQOk+lyTv2r1POFi+GHE3w+YRkYV8DdwnJ//Wi/QqBV8tD5Y3suNw2rHNYSYTyd4rSRE6vO7XuIIbg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDN/5eRDpKkQ9WZjfeqG8rXwWx9hFT9U+CRuGYKty9avwIgWGuB5LQmcVX9LMgqvkW0Ri3T19kXFbFrUbsGHFHp/2M="}]},"maintainers":[{"name":"rsms","email":"rasmus@notion.se"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/lru-fast-0.1.2.tgz_1479144891829_0.9987522438168526"}},"0.2.0":{"name":"lru-fast","version":"0.2.0","description":"finite key-value cache using the Least Recently Used (LRU) algorithm where the most recently used objects are keept in cache while less recently used items are purged","main":"lru.js","typings":"lru.d.ts","scripts":{"test":"node test.js","prepublish":"npm test"},"repository":{"type":"git","url":"git+https://github.com/rsms/js-lru.git"},"keywords":["cache","lru","buffer"],"author":{"name":"Rasmus Andersson","email":"me@rsms.me"},"license":"MIT","bugs":{"url":"https://github.com/rsms/js-lru/issues"},"homepage":"https://github.com/rsms/js-lru#readme","gitHead":"9fb85fa0cc277376320d8e8569f9022ea31883fd","_id":"lru-fast@0.2.0","_shasum":"f0377aaea0b43cc84dc0c92465e74911d9ad7d3a","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.4.0","_npmUser":{"name":"rsms","email":"rasmus@notion.se"},"dist":{"shasum":"f0377aaea0b43cc84dc0c92465e74911d9ad7d3a","tarball":"https://registry.npmjs.org/lru-fast/-/lru-fast-0.2.0.tgz","integrity":"sha512-AgUzkvb8mwW1mAENcYGsbIhh0l708gZxmH2eWyFzCuEH8u9KW3LCcLa47pW8o+1KbfAcmbn/jLBp13e7qgYDDw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFZqCzPESn5nvXWtSEfwXg80rM1pTPdE9Nqt5cHIie5xAiBxlKX/BSPbOx3vlhsEnF5MrVXveRbzuWDSErKbye3l9A=="}]},"maintainers":[{"name":"rsms","email":"rasmus@notion.se"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/lru-fast-0.2.0.tgz_1479148620908_0.9437449551187456"}},"0.2.1":{"name":"lru-fast","version":"0.2.1","description":"finite key-value cache using the Least Recently Used (LRU) algorithm where the most recently used objects are keept in cache while less recently used items are purged","main":"lru.js","typings":"lru.d.ts","scripts":{"test":"node test.js","prepublish":"npm test","benchmark":"node --expose-gc benchmark.js"},"repository":{"type":"git","url":"git+https://github.com/rsms/js-lru.git"},"keywords":["cache","lru","buffer"],"author":{"name":"Rasmus Andersson","email":"me@rsms.me"},"license":"MIT","bugs":{"url":"https://github.com/rsms/js-lru/issues"},"homepage":"https://github.com/rsms/js-lru#readme","gitHead":"c7e31e1593bcf4ce48002b93fdfe308903b79148","_id":"lru-fast@0.2.1","_shasum":"39584b9da68a20748dfa12e9c0ec0f71e1a84d9f","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.4.0","_npmUser":{"name":"rsms","email":"rasmus@notion.se"},"dist":{"shasum":"39584b9da68a20748dfa12e9c0ec0f71e1a84d9f","tarball":"https://registry.npmjs.org/lru-fast/-/lru-fast-0.2.1.tgz","integrity":"sha512-i5iX2tHLoyL5QBkVD4cZ+TyTs5PICxkTc4+BZX7xQUpkbeWzDZ2umRPuH8u0eV895ipcZjuVYJnViIEJacxvuA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICnGFri7Ttrc8lkCOO/qW9dY0FNsNPUJqDcNTL5cP/VkAiEAmns8kZTyYbz3drHN65dN3YUfZqQueDHpWScgaRu0HeI="}]},"maintainers":[{"name":"rsms","email":"rasmus@notion.se"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/lru-fast-0.2.1.tgz_1479152666792_0.9148964476771653"}},"0.2.2":{"name":"lru-fast","version":"0.2.2","description":"finite key-value cache using the Least Recently Used (LRU) algorithm where the most recently used objects are keept in cache while less recently used items are purged","main":"lru.js","typings":"lru.d.ts","scripts":{"test":"node test.js","prepublish":"npm test","benchmark":"node --expose-gc benchmark.js"},"repository":{"type":"git","url":"git+https://github.com/rsms/js-lru.git"},"keywords":["cache","lru","buffer"],"author":{"name":"Rasmus Andersson","email":"me@rsms.me"},"license":"MIT","bugs":{"url":"https://github.com/rsms/js-lru/issues"},"homepage":"https://github.com/rsms/js-lru#readme","gitHead":"ba9d5d28714971a6dcb96f3f92022e308b4e8252","_id":"lru-fast@0.2.2","_shasum":"30c233304cdd9b694b75141d897c52d4d413796c","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.4.0","_npmUser":{"name":"rsms","email":"rasmus@notion.se"},"dist":{"shasum":"30c233304cdd9b694b75141d897c52d4d413796c","tarball":"https://registry.npmjs.org/lru-fast/-/lru-fast-0.2.2.tgz","integrity":"sha512-2lrmGAoTHDPoiTwgaAt3Gw8TXMdHuYNAhBUi2PRoSeSknovaJQUrKK9c07AmFocNcOEoqPpEAZjSo9v3+CB+zg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIElEceOAaBpuL3vwcJvMU1fjgjRkNXcn54BKVNMqcVTyAiEAz/41IxgLLytIIRmtilkqT1VFdqG2nFVl2FK+CuXQuK0="}]},"maintainers":[{"name":"rsms","email":"rasmus@notion.se"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/lru-fast-0.2.2.tgz_1479267056976_0.41125513333827257"}}},"readme":"# Least Recently Used (LRU) cache algorithm\n\n> This is an older version aimed for older JS environments lacking some post-ES5 features like Map and Symbol. If you're targeting a modern web browser or Nodejs, consider using [the latest version](https://github.com/rsms/js-lru) instead.\n\nA finite key-value cache using the [Least Recently Used (LRU)](http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used) cache algorithm where the most recently used objects are keept in cache while less recently used items are purged.\n\nThis implementation is compatible with most JavaScript environments (including ye olde browser) and is very efficient.\n\n## Terminology & design\n\n- Based on a doubly-linked list for low complexity random shuffling of entries.\n\n- The cache object iself has a \"head\" (least recently used entry) and a\n  \"tail\" (most recently used entry).\n\n- The \"head\" and \"tail\" are \"entries\" -- an entry might have a \"newer\" and\n  an \"older\" entry (doubly-linked, \"older\" being close to \"head\" and \"newer\"\n  being closer to \"tail\").\n\n- Key lookup is done through a key-entry mapping native object, which on most \n  platforms mean `O(1)` complexity. This comes at a very low memory cost  (for \n  storing two extra pointers for each entry).\n\nFancy ASCII art illustration of the general design:\n\n```txt\n           entry             entry             entry             entry        \n           ______            ______            ______            ______       \n          | head |.newer => |      |.newer => |      |.newer => | tail |      \n.oldest = |  A   |          |  B   |          |  C   |          |  D   | = .newest\n          |______| <= older.|______| <= older.|______| <= older.|______|      \n                                                                             \n       removed  <--  <--  <--  <--  <--  <--  <--  <--  <--  <--  <--  added\n```\n\n## Example\n\n```js\nlet c = new LRUCache(3)\nc.put('adam',   29)\nc.put('john',   26)\nc.put('angela', 24)\nc.toString()        // -> \"adam:29 < john:26 < angela:24\"\nc.get('john')       // -> 26\n\n// Now 'john' is the most recently used entry, since we just requested it\nc.toString()        // -> \"adam:29 < angela:24 < john:26\"\nc.put('zorro', 141) // -> {key:adam, value:29}\n\n// Because we only have room for 3 entries, put-ing 'zorro' purged 'adam'\nc.toString()        // -> \"angela:24 < john:26 < zorro:141\"\n```\n\n# Usage\n\nJust copy the code on lru.js — for minimal functionality, you only need the lines up until the comment that says \"Following code is optional\".\n\nIf you're really into package managers and love having lots of complicated little files in your project, you can use [`npm install lru-fast`](https://www.npmjs.com/package/lru-fast)\n\nAdditionally:\n\n- Run tests with `npm test`\n- Run benchmarks with `npm run benchmark`\n\n# API\n\n```ts\n\n// An entry holds the key and value, and pointers to any older and newer entries.\ninterface Entry<K,V> {\n  older :Entry<K,V>;\n  newer :Entry<K,V>;\n  key   :K;\n  value :V;\n}\n\nexport class LRUCache<K,V> {\n  // Construct a new cache object which will hold up to limit entries.\n  // When the size == limit, a `put` operation will evict the oldest entry.\n  constructor(limit :number);\n\n  // Current number of items\n  size: number;\n\n  // Maximum number of items this map can hold\n  limit: number;\n\n  // Least recently-used entry\n  oldest: Entry<K,V>;\n\n  // Most recently-used entry\n  newest: Entry<K,V>;\n\n  // Put <value> into the cache associated with <key>. Replaces any existing entry\n  // with the same key.\n  // Returns any entry which was removed to make room for a new entry, or undefined.\n  // Note: The behavior of this method changed between v0.1 and v0.2 where in v0.1\n  // putting multiple values with the same key would store all values (accessible\n  // via forEach and other forms of traversal.) v0.2 stores exactly one value per key.\n  put(key :K, value :V) : Entry<K,V> | undefined;\n\n  // Remove the least recently-used (oldest) entry from the cache.\n  // Returns the removed entry, or undefined if the cache was empty.\n  shift() : Entry<K,V> | undefined;\n\n  // Get and register recent use of <key>.\n  // Returns the value associated with <key> or undefined if not in cache.\n  get(key :K) : V | undefined;\n\n  // Check if <key> is in the cache without registering recent use. Feasible if\n  // you do not want to chage the state of the cache, but only \"peek\" at it.\n  // Returns the entry associated with <key> if found, or undefined if not found.\n  //\n  // Note: The entry returned is managed by the cache (until purged) and thus\n  // contains members with strong references which might be altered at any time by\n  // the cache object. You should look at the returned entry as being immutable.\n  find(key :K) : V | undefined;\n\n  // Update the value of entry with <key>.\n  // Returns the old value, or undefined if entry was not in the cache.\n  set(key :K, value :V) : V | undefined;\n\n  // Remove entry <key> from cache and return its value.\n  // Returns the removed value, or undefined if not found.\n  remove(key :K) : V | undefined;\n\n  // Removes all entries\n  removeAll();\n\n  // Return an array containing all keys of entries stored in the cache object, in\n  // arbitrary order.\n  keys() : Array<K>;\n\n  // Call `fun` for each entry. Starting with the newest entry if `desc` is a true\n  // value, otherwise starts with the oldest (head) enrty and moves towards the tail.\n  // context, Object key, Object value, LRUCache self\n  forEach(\n    fun :(context :any, key :K, value :V, self :LRUCache<K,V>)=>void,\n    context? :any,\n    desc? :boolean\n  ) : void;\n\n  // Returns a JSON (array) representation\n  toJSON() : Array<{key :K, value :V}>;\n\n  // Returns a human-readable text representation\n  toString() : string;\n}\n```\n\nIf you need to perform any form of finalization of items as they are evicted from the cache, wrapping the `shift` method is a good way to do it:\n\n```js\nlet c = new LRUCache(123);\nc.shift = function() {\n  let entry = LRUCache.prototype.shift.call(this);\n  doSomethingWith(entry);\n  return entry;\n}\n```\n\nThe internals calls `shift` as entries need to be evicted, so this method is guaranteed to be called for any item that's removed from the cache. The returned entry must not include any strong references to other entries. See note in the documentation of `LRUCache.prototype.put (Object key, Object value) -> Object entry`.\n\n\n# MIT license\n\nCopyright (c) 2010-2016 Rasmus Andersson <https://rsms.me/>\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","maintainers":[{"name":"rsms","email":"rasmus@notion.se"}],"time":{"modified":"2022-06-19T14:30:10.792Z","created":"2016-09-19T15:32:35.185Z","0.1.0":"2016-09-19T15:32:35.185Z","0.1.1":"2016-11-14T16:21:43.155Z","0.1.2":"2016-11-14T17:34:52.060Z","0.2.0":"2016-11-14T18:37:02.872Z","0.2.1":"2016-11-14T19:44:27.062Z","0.2.2":"2016-11-16T03:30:58.785Z"},"homepage":"https://github.com/rsms/js-lru#readme","keywords":["cache","lru","buffer"],"repository":{"type":"git","url":"git+https://github.com/rsms/js-lru.git"},"author":{"name":"Rasmus Andersson","email":"me@rsms.me"},"bugs":{"url":"https://github.com/rsms/js-lru/issues"},"license":"MIT","readmeFilename":"README.md","users":{"kael":true}}