{"name":"toad-cache","description":"LRU and FIFO caches for Client or Server","version":"2.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","exports":{"import":"./dist/toad-cache.js","require":"./dist/toad-cache.cjs"},"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 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.38.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.4"},"keywords":["LRU","FIFO","cache","client","server","least","recently","used","first","browser"],"gitHead":"6eaa0226e95267de7d0cb36d96e5038170decb4b","_id":"toad-cache@2.0.0","_nodeVersion":"19.8.1","_npmVersion":"9.5.1","dist":{"integrity":"sha512-4stcn4K39594gkCoFeyJd4GwN9R3FaJ73Qi3qJl24YVSyRfDCZwNfBPeBb3Z8f6qnxzsDlO1QbM+YGRRcnEXoA==","shasum":"b890f7719dd7b69f4749f7284fd0bcfc872024dc","tarball":"http://registry-npm.ywwl.com/toad-cache/download/toad-cache-2.0.0.tgz","fileCount":11,"unpackedSize":70924,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCUYGWcPRSbNNIDixdCFe8xiTyPs7hLXvIBlQbNvXLJ5gIgHbr4Us1VMt7j29ltEaYDmwyt+BxNZRlu+eIK1hf4MZQ="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkMXRsACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpuBg/+IPWX0AZqAL8O6iEMIrGEi6vXibwB33+rk+8WeT/Z4DeFfs6k\r\nZDj4iscNsUOwDIsqlsXutlfdrNsmJe0AF+R0q9lGPlKgNliylyJZqhcdlnpf\r\nnoIf12GQvpdtA7ZxLUFgYI7KWIA79r1e0GhRMpbds0lkJsem1b/kqXBOLO4Y\r\nE1jCDYbPSGDxziyOwF2ba6Wiq+OmN8wVQ1EmGtBAqDQXma3eCHQEHerMOiry\r\nTL4+Atyr2ZVPbkh917R/X76PbSS/BfVZPW4rToWYVPlELXbp4UK4tvQDF5Fh\r\niowR/+nH2HQklFqiajb9Z/Uyze/gvs1ggqAYzG0bDhKz5a4kqooxIhUC/CQy\r\njMOLKRDy38gOIor69zHCrbcvmAeQ4Epatvqx4LorKwFWZ/GJTS1mtOz3pRuA\r\nEcqEgbJ6uVyc3T1w4meAYGcY1/o/pW8xHdgoESHp+kfDzSooDUI9vOOWN5JQ\r\nBFvmbz5wzX7wMUs71fLs9fTnnZ0d2soL5qYaGQ/8/tSbcTVKkVNq3lnt2v9T\r\nNO1QGgPXHmNQxZpVSfAJyEOpmcBGGDv4Bw8frShSzwErBKjDh+99LLPD1Tsn\r\ne0IEhuFCdHp2c+ObJapN/P6zTkuGSDozmwxsZCqU3MIUHLBNQta/EqYr3tDl\r\nDiYBe+NvOqfFsTuP12Z47iuQOMOSkrapbYU=\r\n=4amD\r\n-----END PGP SIGNATURE-----\r\n","size":8073,"noattachment":false,"key":"/toad-cache/-/toad-cache-2.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_2.0.0_1680962668092_0.05948938281422578"},"_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":1680962668245,"_cnpm_publish_time":1680962668245,"dist-tags":{"latest":"3.7.4","next":"3.3.1-RC7"}}