{"name":"toad-cache","description":"LRU and FIFO caches for Client or Server","version":"3.1.2","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":{"types":"./toad-cache.d.ts","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 && npm run test:typescript","test:typescript":"tsd","types:generate":"npx -p typescript tsc index.js --declaration --allowJs --emitDeclarationOnly --outDir .","prepublishOnly":"npm run build"},"devDependencies":{"@vitest/coverage-c8":"^0.31.1","@rollup/plugin-terser":"^0.4.0","auto-changelog":"^2.4.0","del-cli":"^5.0.0","eslint":"^8.41.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.22.0","vitest":"^0.31.1","tsd":"^0.28.1","typescript":"^5.0.4"},"keywords":["LRU","FIFO","cache","client","server","least","recently","used","first","browser"],"gitHead":"ec6f0d123fffa62c774d04c6559f43a45142319f","_id":"toad-cache@3.1.2","_nodeVersion":"20.0.0","_npmVersion":"9.6.4","dist":{"integrity":"sha512-dUC9ROefWCv/0b/RLQDMzU6tFqM8EBjYM27xiXl2xc3DQ/R9HL/8/cBRuJ1hG67naFPBlyjBWJwvQLyQu8KUMw==","shasum":"6759a5db877a2550f2e333435f18dc150cf78169","tarball":"http://registry-npm.ywwl.com/toad-cache/download/toad-cache-3.1.2.tgz","fileCount":11,"unpackedSize":116490,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDBMg8D56D5jIkDyZ0NL0Xa2dJdHwtsSBHJ4+i/3EOYUgIgWMRFbN6lMmq94LLkNLuoAYtNruaODsEIlLq3+eprXgg="}],"size":11921,"noattachment":false,"key":"/toad-cache/-/toad-cache-3.1.2.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_3.1.2_1684607119894_0.6832080519645776"},"_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":1684607120084,"_cnpm_publish_time":1684607120084,"dist-tags":{"latest":"3.7.4","next":"3.3.1-RC7"}}