{"_id":"lru-map-cache","name":"lru-map-cache","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"lru-map-cache","version":"0.1.0","description":"A simple and fast LRU cache using the native Map class.","main":"src/index.js","directories":{"test":"tests"},"scripts":{"test":"jest"},"repository":{"type":"git","url":"git+https://github.com/helloanoop/lru-map-cache.git"},"keywords":["lru","cache","map"],"author":{"name":"Anoop M D","email":"anoop.md1421@gmail.com"},"license":"ISC","bugs":{"url":"https://github.com/helloanoop/lru-map-cache/issues"},"homepage":"https://github.com/helloanoop/lru-map-cache#readme","devDependencies":{"jest":"^29.5.0"},"gitHead":"ee5a8557b02730d56948e8e4dae42272e9ab1f8b","_id":"lru-map-cache@0.1.0","_nodeVersion":"16.19.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-r1lasvJbg3lrTS37W5h4Ugy9miaWluYqviZGbfH9A6AbjxSDJCtPNqtGr5MRl/RG/EfYrwe07DC4zQEBnY2q4w==","shasum":"5f748b645e36ed5e41a5dca0bab4c52c301dae29","tarball":"https://registry.npmjs.org/lru-map-cache/-/lru-map-cache-0.1.0.tgz","fileCount":4,"unpackedSize":4232,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIG0t2YUjgFx9OSuSzhtFUCKUbzlG2oBn0wcy5p+j7qZ8AiBDkqEpAmdzJl2zafpXr6Iv5vt/uvg6SwlGgyFjjuYnVg=="}]},"_npmUser":{"name":"anoopmd","email":"anoop.md1421@gmail.com"},"maintainers":[{"name":"anoopmd","email":"anoop.md1421@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/lru-map-cache_0.1.0_1686128673171_0.01772919287227226"},"_hasShrinkwrap":false}},"time":{"created":"2023-06-07T09:04:33.171Z","0.1.0":"2023-06-07T09:04:33.342Z","modified":"2023-06-07T09:04:33.528Z"},"maintainers":[{"name":"anoopmd","email":"anoop.md1421@gmail.com"}],"description":"A simple and fast LRU cache using the native Map class.","homepage":"https://github.com/helloanoop/lru-map-cache#readme","keywords":["lru","cache","map"],"repository":{"type":"git","url":"git+https://github.com/helloanoop/lru-map-cache.git"},"author":{"name":"Anoop M D","email":"anoop.md1421@gmail.com"},"bugs":{"url":"https://github.com/helloanoop/lru-map-cache/issues"},"license":"ISC","readme":"# lru-map-cache\n\nA simple and fast LRU cache using the native `Map` class.\n\n## Installation\n```\nnpm install lru-map-cache\n```\n\n## Usage\n```javascript\nconst LRUCache = require('lru-map-cache');\n\nconst cache = new LRUCache(3);\n\ncache.set('a', 1);\ncache.set('b', 2);\ncache.set('c', 3);\ncache.set('d', 4);\n\ncache.get('a'); // undefined\ncache.get('b'); // 2\ncache.get('c'); // 3\ncache.get('d'); // 4\n```\n\n## How it works\nThe Map data structure in JavaScript maintains the order of keys, allowing us to leverage it for implementing an efficient LRU cache.\n\nEach time a get or set operation is performed, the corresponding key is deleted and re-inserted into the Map. This process ensures that the key is moved to the end of the Map, indicating its most recently used status.\n\nWhen the cache reaches its maximum capacity, the first key in the Map (the least recently used key) is deleted to make space for new entries.\n\n## API\n### `LRUCache(capacity)`\nCreates a new cache with the given capacity.\n\n### `set(key, value)`\nSets the value for the given key.\n\n### `get(key)`\nGets the value for the given key.\n\n### `delete(key)`\nDeletes the value for the given key.\n\n### `clear()`\nClears the cache.\n\n### `size()`\nReturns the number of items in the cache.\n\n### `capacity()`\nReturns the maximum capacity of the cache.\n\n### `has(key)`\nReturns true if the cache contains the given key.\n\n### `keys()`\nReturns an iterator for the keys in the cache.\n\n### `values()`\nReturns an iterator for the values in the cache.\n\n### License\n[MIT](LICENSE)\n","readmeFilename":"readme.md"}