{"name":"toad-cache","description":"LRU cache for Client or Server","version":"1.0.0","homepage":"https://github.com/kibertoad/toad-cache","author":{"name":"Igor Savin","email":"kibertoad@gmail.com"},"repository":{"type":"git","url":"git://github.com/kibertoad/toad-cache.git"},"bugs":{"url":"https://github.com/kibertoad/toad-cache/issues"},"license":"MIT","source":"index.js","main":"dist/toad-cache.cjs","module":"dist/toad-cache.esm.js","type":"module","sourceType":"module","types":"toad-cache.d.ts","engines":{"node":">=12"},"engineStrict":true,"scripts":{"build":"del-cli dist && del-cli coverage && npm run test:ci","benchmark":"node benchmark.js","changelog":"auto-changelog -p","lint":"eslint *.js src/*.js test/*.js","lint:fix":"eslint --fix *.js src/*.js test/*.js","format":"prettier --write \"{src,test}/**/*.js\" benchmark.js ","rollup":"rollup --config","test":"vitest","test:coverage":"npm run rollup && npm run test -- --coverage","test:ci":"npm run rollup && npm run lint && npm run test:coverage","types":"npx -p typescript tsc src/lru.js --declaration --allowJs --emitDeclarationOnly --outDir .","prepublishOnly":"npm run build"},"devDependencies":{"@vitest/coverage-c8":"0.29.8","@rollup/plugin-terser":"^0.4.0","auto-changelog":"^2.4.0","del-cli":"^5.0.0","eslint":"^8.37.0","eslint-config-prettier":"^8.8.0","eslint-plugin-import":"^2.27.5","eslint-plugin-prettier":"^4.2.1","precise":"^2.0.1","rollup":"^3.20.2","vitest":"0.29.8","typescript":"^5.0.3"},"keywords":["LRU","FIFO","cache","client","server","least","recently","used","first","browser"],"gitHead":"634a2d4166ab7d3b145c2ea93af4425e7a1df423","_id":"toad-cache@1.0.0","_nodeVersion":"18.5.0","_npmVersion":"8.12.1","dist":{"integrity":"sha512-m3I5JB8mTDEUgPq4rsuSyAYu1hLBe3xznf4dGR8eoIVLbdW6mRJnaHKh/5sadqbdfqQXlWuGJTN1CPThg9qcug==","shasum":"6704e5b1d61031fa222c50a31a3e34c4f3515da6","tarball":"http://registry-npm.ywwl.com/toad-cache/download/toad-cache-1.0.0.tgz","fileCount":11,"unpackedSize":47752,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFHkOGLu+XJZK5aupCSkJPVAxUDQkMQ8ER6mIi/N+Eh1AiAR84yglb9kUawHU1XOe5VCFFtq4iiOEqBy3pX6l11rrw=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkKb16ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqH7RAAiDBQykhUCz9J1fCJlrmb5pYCk/ajFZuk3iYR8X8BMBlG9hN4\r\n+hlkSqNyGKFAkqssW5Hlm1mhcEsPnYnzGnBiKbbxJvtUBnmkV7c9Ptxwf/EU\r\ngY3fdZPldGH/LRNg+skxxqjhhriho1S9SlTUIMIJtOuQ3HcKLYOEm9DAYKC2\r\n443Disjodfgaa17G4dUYd932Udxpt8p1Bh8a83qp8uFtCtSYxgzVDH7fqoS0\r\nxFWg+nmg/QhTo8ot7EgXVTxQU1OKzUS2nSejO71dOvv9cEL2msPRAxHpg00/\r\njek28noxq58dsu3snV8KsUqmPaEmMKP4cuDHr13U0kfDhhSRgvVy6zUFH0Gx\r\ncaE5P0OJj4iUK9vXTrz1ot7wB91tMZAp99+J/nX3T9DsGMU7NF2+RBIgTMD5\r\n1nc+2neAh85rjlAyWQs1ySHv9NW8Zzez+2lMDUXiD6ctSyuJ5whmkReASV0S\r\nU6Lf9JsYd9DRu9F8gnHnAt5exYNfjSze98W53qh2AnML9p8plZWjJ0r4V9yJ\r\nYZDWXkW0aj7B/LTe4/qxPV806vy74fVT+DBkUlijKp2M3RiQV9nuY9nJuFaI\r\nRkbaXqLuCg3yjykuHOn7Dyctb1PGY7Jyze41yfAYt4vXfwfsb6CLAqwx6+Ki\r\n/Knun2OBtdfnMz/TXHDktrRhj7ZNaxgfxrI=\r\n=XxpN\r\n-----END PGP SIGNATURE-----\r\n","size":6972,"noattachment":false,"key":"/toad-cache/-/toad-cache-1.0.0.tgz"},"_npmUser":{"name":"kibertoad","email":"iselwin@gmail.com"},"directories":{},"maintainers":[{"name":"kibertoad","email":"iselwin@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/toad-cache_1.0.0_1680457082099_0.7778973998341345"},"_hasShrinkwrap":false,"readme":"# Toad Cache\n\n[![NPM Version](https://img.shields.io/npm/v/toad-cache.svg)](https://npmjs.org/package/toad-cache)\n[![NPM Downloads](https://img.shields.io/npm/dm/toad-cache.svg)](https://npmjs.org/package/toad-cache)\n![](https://github.com/kibertoad/toad-cache/workflows/ci/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/kibertoad/toad-cache/badge.svg?branch=main)](https://coveralls.io/r/kibertoad/toad-cache?branch=main)\n\nLeast-Recently-Used and First-In-First-Out caches for Client or Server.\n\n## Getting started\n\n```javascript\nimport { Lru, Fifo } from 'toad-cache'\nconst lruCache = new Lru(max, ttl = 0)\nconst fifoCache = new Fifo(max, ttl = 0)\n```\n\n## clear\n\n### Method\n\nClears the contents of the cache\n\n**Example**\n\n```javascript\ncache.clear()\n```\n\n## delete\n\n### Method\n\nRemoves item from cache\n\n    param  {String} key Item key\n\n**Example**\n\n```javascript\ncache.delete('myKey')\n```\n\n## deleteMany\n\n### Method\n\nRemoves items from cache\n\n    param  {String[]} keys Item keys\n\n**Example**\n\n```javascript\ncache.deleteMany(['myKey', 'myKey2'])\n```\n\n## evict\n\n### Method\n\nEvicts the least recently used item from cache\n\n**Example**\n\n```javascript\ncache.evict()\n```\n\n## expiresAt\n\n### Method\n\nGets expiration time for cached item\n\n    param  {String} key Item key\n    return {Mixed}      Undefined or number (epoch time)\n\n**Example**\n\n```javascript\nconst item = cache.expiresAt('myKey')\n```\n\n## first\n\n### Property\n\nItem in \"first\" or \"bottom\" position\n\n**Example**\n\n```javascript\nconst cache = new Lru()\n\ncache.first // null - it's a new cache!\n```\n\n## get\n\n### Method\n\nGets cached item and marks it as recently used (pushes to the back of the list of the candidates for the eviction)\n\n    param  {String} key Item key\n    return {Mixed}      Undefined or Item value\n\n**Example**\n\n```javascript\nconst item = cache.get('myKey')\n```\n\n## getMany\n\n### Method\n\nGets multiple cached items and marks them as recently used (pushes to the back of the list of the candidates for the eviction)\n\n    param  {String[]} keys Item keys\n    return {Mixed[]}      Undefined or Item values\n\n**Example**\n\n```javascript\nconst item = cache.getMany(['myKey', 'myKey2'])\n```\n\n## keys\n\n### Method\n\nReturns an `Array` of cache item keys.\n\n    return {Array} Array of keys\n\n**Example**\n\n```javascript\nconsole.log(cache.keys())\n```\n\n## max\n\n### Property\n\nMax items to hold in cache (1000)\n\n**Example**\n\n```javascript\nconst cache = new Lru(500)\n\ncache.max // 500\n```\n\n## last\n\n### Property\n\nItem in \"last\" or \"top\" position\n\n**Example**\n\n```javascript\nconst cache = new Lru()\n\ncache.last // null - it's a new cache!\n```\n\n## set\n\n### Method\n\nSets item in cache as `first`\n\n    param  {String} key   Item key\n    param  {Mixed}  value Item value\n\n**Example**\n\n```javascript\ncache.set('myKey', { prop: true })\n```\n\n## size\n\n### Property\n\nNumber of items in cache\n\n**Example**\n\n```javascript\nconst cache = new Lru()\n\ncache.size // 0 - it's a new cache!\n```\n\n## ttl\n\n### Property\n\nMilliseconds an item will remain in cache; lazy expiration upon next `get()` of an item\n\n**Example**\n\n```javascript\nconst cache = new Lru()\n\ncache.ttl = 3e4\n```\n\n## Hit/miss/expiration tracking\n\nIn case you want to gather information on cache hit/miss/expiration ratio, as well as cache size and eviction statistics, you can use LruHitStatistics class:\n\n```js\nconst sharedRecord = new HitStatisticsRecord() // if you want to use single record object for all of caches, create it manually and pass to each cache\n\nconst cache = new LruHitStatistics({\n  cacheId: 'some-cache-id',\n  globalStatisticsRecord: sharedRecord,\n  statisticTtlInHours: 24, // how often to reset statistics. On every rotation previously accumulated data is removed\n  max: 1000,\n  ttlInMsecs: 0,\n})\n```\n\nYou can retrieve accumulated statistics from the cache, or from the record directly:\n\n```js\n// this is the same\nconst statistics = sharedRecord.getStatistics()\nconst alsoStatistics = cache.getStatistics()\n\n/*\n{\n  'some-cache-id': {\n    '2023-04-06': {\n      cacheSize: 100, // how many elements does cache currently have\n      evictions: 5, // how many elements were evicted due to cache being at max capacity    \n      expirations: 0, // how many elements were removed during get due to their ttl being exceeded\n      hits: 0, // how many times element was successfully retrieved from cache during get\n      emptyHits: 0, // out of all hits, how many were null, undefined or ''?\n      falsyHits: 0, // out of all hits, how many were falsy?      \n      misses: 1, // how many times element was not in cache or expired during get\n      invalidateOne: 1, // how many times element was invalidated individually\n      invalidateAll: 2, // how many times entire cache was invalidated\n      sets: 0, // how many times new element was added      \n    },\n  },\n}\n\nNote that date here reflects start of the rotation. If statistics weren't rotated yet, and another day started, it will still be counted against the day of the rotation start\n*/\n```\n\n## License\n\nCopyright (c) 2023 Igor Savin\n\nBased on [tiny-lru](https://github.com/avoidwork/tiny-lru), created by Jason Mulligan\n\nLicensed under the MIT license.\n","publish_time":1680457082279,"_cnpm_publish_time":1680457082279,"dist-tags":{"latest":"3.7.4","next":"3.3.1-RC7"}}