{"_id":"@avolgha/timed-cache","_rev":"1-16cbe1524a034be2e15fc51dc5b3e121","name":"@avolgha/timed-cache","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@avolgha/timed-cache","version":"1.0.0","description":"<p><h2 align=\"center\">timed-cache</h2></p>\r <p align=\"center\">Store values for a limited time in a kind of map.</p>","packageManager":"pnpm@8.1.1","bin":{"timed-cache":"dist/timed-cache.cjs.js"},"main":"dist/timed-cache.cjs.js","module":"dist/timed-cache.esm.js","repository":{"type":"git","url":"git+https://github.com/avolgha/timed-cache.git"},"author":{"name":"avolgha","email":"avolgha@gmail.com","url":"github.com/avolgha"},"license":"BSD-3 Clause Clear","bugs":{"url":"https://github.com/avolgha/timed-cache/issues"},"homepage":"https://github.com/avolgha/timed-cache","devDependencies":{"@eslint/create-config":"^0.4.2","@rollup/plugin-terser":"^0.4.0","@rollup/plugin-typescript":"^11.0.0","@types/node":"^18.15.11","@typescript-eslint/eslint-plugin":"^5.54.0","@typescript-eslint/parser":"^5.54.0","eslint":"^8.35.0","rollup":"^3.18.0","tslib":"^2.5.0","typescript":"^4.9.5"},"scripts":{"bundle":"rollup -c","watch":"rollup -cw","lint":"eslint src/"},"_id":"@avolgha/timed-cache@1.0.0","_integrity":"sha512-e4JObt+ptCnM58UM/t7expC8Cd1NKmzuB32YFieHepO1Qt+2Ydfel9QMNIRiRDTm1ebiYtSdxWEHLwVQjXBJbA==","_resolved":"C:\\Users\\user\\AppData\\Local\\Temp\\d88d1ce06ebcd67c2e972bcab8a08f47\\avolgha-timed-cache-1.0.0.tgz","_from":"file:avolgha-timed-cache-1.0.0.tgz","_nodeVersion":"20.3.1","_npmVersion":"8.7.0","dist":{"integrity":"sha512-e4JObt+ptCnM58UM/t7expC8Cd1NKmzuB32YFieHepO1Qt+2Ydfel9QMNIRiRDTm1ebiYtSdxWEHLwVQjXBJbA==","shasum":"02dfc9350e3fc8624046db5aae3dadd421304f5a","tarball":"https://registry.npmjs.org/@avolgha/timed-cache/-/timed-cache-1.0.0.tgz","fileCount":8,"unpackedSize":8145,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIE9bEkfMqM+xTNfe8La6Arx9ZFqJe8k5KUGtTc9650J7AiA4Ge99xlA4ZMbnUfUSDVUu9gvHJnhaeZJq6ogBQaRu1Q=="}]},"_npmUser":{"name":"avolgha","email":"avolgha@gmail.com"},"directories":{},"maintainers":[{"name":"avolgha","email":"avolgha@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/timed-cache_1.0.0_1688662819791_0.09582519726139549"},"_hasShrinkwrap":false},"1.0.1":{"name":"@avolgha/timed-cache","version":"1.0.1","description":"<p><h2 align=\"center\">timed-cache</h2></p>\r <p align=\"center\">Store values for a limited time in a kind of map.</p>","packageManager":"pnpm@8.1.1","bin":{"timed-cache":"dist/timed-cache.cjs.js"},"main":"dist/timed-cache.cjs.js","module":"dist/timed-cache.esm.js","repository":{"type":"git","url":"git+https://github.com/avolgha/timed-cache.git"},"author":{"name":"avolgha","email":"avolgha@gmail.com","url":"github.com/avolgha"},"license":"BSD-3 Clause Clear","bugs":{"url":"https://github.com/avolgha/timed-cache/issues"},"homepage":"https://github.com/avolgha/timed-cache","devDependencies":{"@eslint/create-config":"^0.4.2","@rollup/plugin-terser":"^0.4.0","@rollup/plugin-typescript":"^11.0.0","@types/node":"^18.15.11","@typescript-eslint/eslint-plugin":"^5.54.0","@typescript-eslint/parser":"^5.54.0","eslint":"^8.35.0","rollup":"^3.18.0","tslib":"^2.5.0","typescript":"^4.9.5"},"scripts":{"bundle":"rollup -c","watch":"rollup -cw","lint":"eslint src/"},"_id":"@avolgha/timed-cache@1.0.1","_integrity":"sha512-zkanUGnq6Zx5yEy78G1rUQamfhHh5qKKRAx6LJkQZtrblWClQOgIb6MNToZ9tFO77twWJ5iRrIkUe9H4ru5pYA==","_resolved":"C:\\Users\\user\\AppData\\Local\\Temp\\0d12510351f4903214a1b630dda5c577\\avolgha-timed-cache-1.0.1.tgz","_from":"file:avolgha-timed-cache-1.0.1.tgz","_nodeVersion":"20.3.1","_npmVersion":"8.7.0","dist":{"integrity":"sha512-zkanUGnq6Zx5yEy78G1rUQamfhHh5qKKRAx6LJkQZtrblWClQOgIb6MNToZ9tFO77twWJ5iRrIkUe9H4ru5pYA==","shasum":"aaa2b9c0baa263cbfec7ab211a549c726a2f9833","tarball":"https://registry.npmjs.org/@avolgha/timed-cache/-/timed-cache-1.0.1.tgz","fileCount":8,"unpackedSize":10394,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCbJ3RqoP5Bab6v+6ZEiBIVjsnH/Ow+3BRZ9pPT0uEB4AIgckNfsQxHQnvrZdlUu5OiQTy3DgmRdGXuGkxDNwDIpfM="}]},"_npmUser":{"name":"avolgha","email":"avolgha@gmail.com"},"directories":{},"maintainers":[{"name":"avolgha","email":"avolgha@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/timed-cache_1.0.1_1689265515271_0.32581246757532356"},"_hasShrinkwrap":false}},"time":{"created":"2023-07-06T17:00:19.711Z","1.0.0":"2023-07-06T17:00:20.013Z","modified":"2023-07-13T16:25:15.561Z","1.0.1":"2023-07-13T16:25:15.463Z"},"maintainers":[{"name":"avolgha","email":"avolgha@gmail.com"}],"description":"<p><h2 align=\"center\">timed-cache</h2></p>\r <p align=\"center\">Store values for a limited time in a kind of map.</p>","homepage":"https://github.com/avolgha/timed-cache","repository":{"type":"git","url":"git+https://github.com/avolgha/timed-cache.git"},"author":{"name":"avolgha","email":"avolgha@gmail.com","url":"github.com/avolgha"},"bugs":{"url":"https://github.com/avolgha/timed-cache/issues"},"license":"BSD-3 Clause Clear","readme":"<p><h2 align=\"center\">timed-cache</h2></p>\r\n<p align=\"center\">Store values for a limited time in a kind of map.</p>\r\n\r\n## Usage\r\n\r\n````typescript\r\nimport TimedCache from \"@avolgha/timed-cache\";\r\n\r\nconst sleep = (time: number) => new Promise((res) => setTimeout(res, time));\r\n\r\n(async () => {\r\n\tconst cache = new TimedCache(1000 * 3);\r\n\r\n\tcache.set(\"foo\", \"bar\");\r\n\r\n\tconsole.log(cache.get(\"foo\"));\r\n\t// => \"bar\"\r\n\r\n\tawait sleep(1000 * 2);\r\n\r\n\tconsole.log(cache.get(\"foo\"));\r\n\t// => \"bar\";\r\n\r\n\tawait sleep(1000 * 2);\r\n\r\n\tconsole.log(cache.get(\"foo\"));\r\n\t// => null\r\n})();\r\n````\r\n\r\n## Todos\r\n\r\n##### done in v1.0.1\r\n- [x] Create a way to access stored keys.\r\n- [x] Give the developer access to the remaining time of an item.\r\n- [x] Create a `forEach` function.\r\n- [x] Let developer optionally choose a time for the items removal.\r\n\r\n## Configuration\r\n\r\nYou can crate a cache by instantiating the default export of the `@avolgha/timed-cache` package.  \r\nOptionally, you can specify the time after that an item of the map should be deleted. *This time has\r\nto be specified in milliseconds.*\r\n\r\n````typescript\r\nconst cache = new TimedCache();\r\n// => items will be deleted after 5 minutes\r\n\r\nconst cache = new TimedCache(1000 * 3);\r\n// => items will be deleted after 3 seconds\r\n````\r\n\r\nA cache can only contain one type of item. You can specify this type with a generic on the `TimedCache`\r\nclass:\r\n\r\n````typescript\r\nconst stringCache = new TimedCache<string>();\r\n````\r\n\r\nIf you don't specify any generic, TypeScript will refer to `any` as the default type.\r\n\r\n## Methods\r\n\r\nTo add items to the map, you can use the `set` method. It requires two arguments, a key and a value.\r\n\r\n````typescript\r\nconst key: string = \"foo\";\r\nconst value: string = \"bar\";\r\n\r\ncache.set(key, value);\r\n\r\n// you can also specify a custom time for each item:\r\ncache.set(key, value, 1000);\r\n````\r\n\r\nIf you then want to get a specific item from the cache, you can use the `get` method. This method\r\nonly requires the key of the item you want to get.\r\n\r\n````typescript\r\nconst key = \"foo\";\r\nconst value = cache.get(key);\r\n````\r\n\r\nLike `get` you can also iterate over every item in the cache.\r\n\r\n````typescript\r\ncache.forEach((value) => {\r\n\t// noop\r\n});\r\n````\r\n\r\nIf you want to get all the stored keys in the cache, you have to access them through the `keys`\r\nproperty.\r\n\r\n````typescript\r\nconst keys = cache.keys;\r\n````\r\n\r\nIf you then not longer need the value, you can remove it with the `remove` function. This function\r\naswell only needs the key of the item. And additionally, it returns the item you removed.\r\n\r\n````typescript\r\nconst key = \"foo\";\r\nconst removed = cache.remove(key);\r\n````\r\n\r\nTo check if there is an item with a given key, you can check this with the help of the `has`\r\nfunction. It only requires the key of the item you want to check for existance.\r\n\r\n````typescript\r\nconst key = \"foo\";\r\nif (cache.has(key)) {\r\n\tconsole.log(`\"${cache.get(key)}\" is in the cache!`);\r\n}\r\n````\r\n\r\nIf you want to see the remaining time of the entry in the cache, you can use the `remaining` function.\r\n\r\n````typescript\r\nconst key = \"foo\";\r\n\r\nconst timeRemaining = cache.remaining(key);\r\n````\r\n","readmeFilename":"README.md"}