{"_id":"@denox/lru_store","name":"@denox/lru_store","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"module":"./esm/mod.js","main":"./script/mod.js","types":"./types/mod.d.ts","name":"@denox/lru_store","version":"1.0.0","description":"Extension of Map to become an LRU Cache.","license":"MIT","keywords":["lru","cache","store"],"repository":{"type":"git","url":"git+https://github.com/claudiuandrei/lru.git"},"bugs":{"url":"https://github.com/claudiuandrei/lru/issues"},"engines":{"node":">=11.0.0"},"exports":{".":{"import":{"default":"./esm/mod.js","types":"./types/mod.d.ts"},"require":{"default":"./script/mod.js","types":"./types/mod.d.ts"}}},"scripts":{"test":"node test_runner.js"},"devDependencies":{"@types/node":"16.11.37","chalk":"4.1.2","@deno/shim-deno-test":"~0.3.3"},"gitHead":"75908d5e43c205cb5141ca759915d7d5c66c045f","homepage":"https://github.com/claudiuandrei/lru#readme","_id":"@denox/lru_store@1.0.0","_nodeVersion":"18.11.0","_npmVersion":"8.19.2","dist":{"integrity":"sha512-/jCjtZ8yzDBdi8vE5vr/PK3jc30pHxaIokrtqNx1GkCfWgkCktT3mzvg0GXWOXODJ/lxBjInGPsg1ZQ05sG0Mw==","shasum":"349584e070eadbcd5c66565936694bde997da339","tarball":"https://registry.npmjs.org/@denox/lru_store/-/lru_store-1.0.0.tgz","fileCount":8,"unpackedSize":7925,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCwAiz5tOUIorWcPzyIT7GjohURC0zTOlArK7zVHTvAlwIhAONvznT623iRVx5BrtcWXHOq8+VN6Gw56vmUDS3M3HRM"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjaBWnACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoxLw/8CQoPiPpCNxqCgMI2qyF2opJUb1fU9P5xYkx3qrSWF5I7nGRh\r\ndllNX6ha1v6hyzmzA/CuSw6I0xSLYzbCrVYnJNNJ87E9lcxGxR41cT9ms7Uh\r\nfOgekLFXfJZMXXPzx6gx8RJXpejSUQJGGdAPPWNgI+npp/sUZhe0c3W/wf2x\r\ndTaVyw2grc2vOPlnA8z7TZ/en4UVnnXj2gcfTEYXBGF4fBZ1HKiBQpVd4CXg\r\nioINexw+RZumTvznApD588gg0o43Huek+4E363DDeT3LPg4mT0OknLBwCwRl\r\nM47CI3SADwxTDOU0gKpVltEN9mXfu42+XcB0pVelZ8TjST4ETU8kKK1E3cwM\r\n6CP6rbnWAMos76aMfJ8P5nsMEG0ltJ9vmEgu10jK7q8Y+nnViFqURHrfoF0P\r\n8jMXmdVg6L7z6o8VPyS1mC7LSR3MhLElH0WCwbZuyX7BYnP7viTbIVjAoYAV\r\niNpQlWGkAk/TaXEi4rQDdZW8vxXdAVDbNlyhuZ1LB6KO+P257/bgt/8+W9Xg\r\n0OHd7vF+tzRft/rUHKlTcrnoHNFzoc4iISMx1DWyBSozYbel8QrqR27Tm+Zd\r\nlr6aVnDxrr3qA1Gor/im/K5w4xA5odynNTh6ZdcL+lD9WSwzx0WqJXcjBcCq\r\nJnc3UmGfZg+rNXAleh++UxtQSea4fril3p0=\r\n=U8Xm\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"claudiuandrei","email":"claudiu.andrei@gmail.com"},"directories":{},"maintainers":[{"name":"claudiuandrei","email":"claudiu.andrei@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/lru_store_1.0.0_1667765671007_0.4645977830929333"},"_hasShrinkwrap":false}},"time":{"created":"2022-11-06T20:14:30.915Z","1.0.0":"2022-11-06T20:14:31.164Z","modified":"2022-11-06T20:14:31.338Z"},"maintainers":[{"name":"claudiuandrei","email":"claudiu.andrei@gmail.com"}],"description":"Extension of Map to become an LRU Cache.","homepage":"https://github.com/claudiuandrei/lru#readme","keywords":["lru","cache","store"],"repository":{"type":"git","url":"git+https://github.com/claudiuandrei/lru.git"},"bugs":{"url":"https://github.com/claudiuandrei/lru/issues"},"license":"MIT","readme":"# LRU Store\n\nThis is an LRU Cache implementation using Map as the native Map guarantees the order of the of the [key, value] pairs to be maintained in the insertion order.\n\nThe LRU allows to use anything as key/value just like Map, and it follows the same interface as a Map, with the addition of `peek` method and `maxSize` property.\n\n## Usage Deno\n\n```ts\nimport LRU from \"https://deno.land/x/lru_store/mod.ts\";\n```\n\n## Usage Node\n\n```bash\nnpm install --save @denox/lru_store\n```\n\n```js\nimport LRU from \"@denox/lru_store\";\n```\n\n## API\n\n### Initialization\n\nThe first argument is `maxSize` and it is required, the second one is `entries` and it is optional, allowing prepopulating the cache.\n\n```js\nconst lru = new LRU(100); // Creates an empty LRU Cache with 100 entries capacity\nconst lruWithData = new LRU(100, [\n\t[\"key1\", \"value1\"],\n\t[\"key2\", \"value2\"],\n]); // Creates an LRU Cache with 2 entries and 100 entries capacity\n```\n\n### Set\n\nAdd a key/value pair to the cache. If the cache will exceed capacity, it will evict the oldest key/value pair.\n\n```js\nlru.set(\"key\", \"value\");\n```\n\n### Get\n\nRetrieve a value from the cache based on the keys, it will return undefined if the key is not found.\n\n```js\nlru.get(\"key\");\n```\n\n### Peek\n\nRetrieve the value from the cache based on the key, similar with `get` but without changing the priority of the queue.\n\n```js\n// Same behavior as get but without moving the key/value to the end of the eviction queue\nlru.peek(\"key\");\n```\n\n### Has\n\nCheck if a key is inside the LRU, returning `true` if found or `false` if not.\n\n```js\nlru.has(\"key\");\n```\n\n### Delete\n\nEvict the key/value pair based on key, returning `true` if found or `false` if not.\n\n```js\nlru.delete(\"key\");\n```\n\n### Clear\n\nEvict everything from the cache, leaving the LRU empty.\n\n```js\nlru.clear();\n```\n\n### Size\n\nGet the current size of the LRU.\n\n```js\nlru.size; // Number\n```\n\n### MaxSize\n\nGet the set capacity of the LRU, `size` should never exceed `maxSize`.\n\n```js\nlru.maxSize; // Number\n```\n\n### Keys, Values, Entries\n\nGet the iterators for `keys`, `values` or `entries` in the eviction order.\n\n```js\nArray.from(lru.keys()); // [key1, key2, ...]\nArray.from(lru.values()); // [value1, value2, ...]\nArray.from(lru.entries()); // [[key1, value1], [key2, value2], ...]\n```\n\n### ForEach\n\nIterate over the LRU entries in the eviction order.\n\n```js\nlru.forEach((value, key, lru) => {\n\t//...\n});\n```\n\n## License\n\n[MIT](LICENSE)\n","readmeFilename":"README.md"}