{"name":"cache-manager-fs-hash","version":"3.0.0","main":"index.js","engines":{"node":">=18.0.0"},"description":"file system store for node cache manager","author":{"name":"Roland Starke"},"license":"MIT","keywords":["cache-manager","storage","filesystem","disk-store","key-value-store"],"repository":{"type":"git","url":"git+https://github.com/rolandstarke/node-cache-manager-fs-hash.git"},"bugs":{"url":"https://github.com/rolandstarke/node-cache-manager-fs-hash/issues"},"scripts":{"test":"node --test"},"devDependencies":{"cache-manager":"^7.2.0","cache-manager-v7":"npm:cache-manager@^7.2.0","cache-manager-v5":"npm:cache-manager@^5.5.1","cache-manager-v4":"npm:cache-manager@^4.1.0","cache-manager-fs-hash-v2":"npm:cache-manager-fs-hash@^2.0.0"},"dependencies":{"lockfile":"^1.0.4"},"_id":"cache-manager-fs-hash@3.0.0","gitHead":"f9e34f4ebcc704209f43000685b29671e26ca40c","homepage":"https://github.com/rolandstarke/node-cache-manager-fs-hash#readme","_nodeVersion":"20.19.4","_npmVersion":"10.8.2","dist":{"integrity":"sha512-uFl2EOuIdz5bLIjcRbR5cAxt9JdKQ5jQ6r7w5LXs1V+ls9I232nLVfaEHwK5h+isbV7j2z7ceaMe8lvr17BMVA==","shasum":"a0db02fcacc35680af658ff2f0280fb33ece0c35","tarball":"http://registry-npm.ywwl.com/cache-manager-fs-hash/download/cache-manager-fs-hash-3.0.0.tgz","fileCount":7,"unpackedSize":26000,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIGNoSLfYi/ICT+v5BAPYyBBWxWK9zM9OX+L7LGYxqbedAiAPfMMYxm6A7EDZIheCE7kkyg/Sp1FdHwVzMYd5FzoNRw=="}],"size":7299,"noattachment":false,"key":"/cache-manager-fs-hash/-/cache-manager-fs-hash-3.0.0.tgz"},"_npmUser":{"name":"rolandstarke","email":"programmierzeugs@gmail.com"},"directories":{},"maintainers":[{"name":"rolandstarke","email":"programmierzeugs@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/cache-manager-fs-hash_3.0.0_1756566866940_0.29512183783288704"},"_hasShrinkwrap":false,"readme":"# Node Cache Manager store for Filesystem\n\n[![Build](https://github.com/rolandstarke/node-cache-manager-fs-hash/actions/workflows/node.js.yml/badge.svg)](https://github.com/rolandstarke/node-cache-manager-fs-hash/actions/workflows/node.js.yml)\n[![npm package](https://img.shields.io/npm/v/cache-manager-fs-hash.svg)](https://www.npmjs.com/package/cache-manager-fs-hash)\n[![node](https://img.shields.io/node/v/cache-manager-fs-hash.svg)](https://nodejs.org)\n\nPackage to cache key-value pairs in JSON files.\n\n## Installation\n\n```sh\nnpm install cache-manager-fs-hash\n```\n\n## Features\n\n* Saves anything that is `JSON.stringify`-able to disk\n* Buffers are saved as well (if they reach a certain size they will be stored to separate files)\n* Works well with the cluster module\n\n## Usage example\n\nHere is an example that demonstrates how to use the filesystem cache store.\n\n```javascript\nconst { DiskStore } = require('cache-manager-fs-hash');\n\nconst diskStore = new DiskStore({\n    path: 'diskcache', // path for cached files (default: cache)\n    ttl: 60 * 60 * 1000, // time to live in milliseconds \n                         // (default: never expires)\n    zip: true, // zip files to save disk space (default: false)\n    hash: false, // keys are hashed to generate filenames (default: true)\n                 // set to false to use plain keys as filenames\n});\n\n(async () => {\n    await diskStore.set('key', 'value');\n    console.log(await diskStore.get('key')); // \"value\"\n\n    await diskStore.del('key');\n    console.log(await diskStore.get('key')); // undefined\n\n    await diskStore.set('key', 'value', 1000); // with custom TTL\n    console.log(await diskStore.ttl('key')); // 999 milliseconds\n\n    // delete stored files\n    await diskStore.reset();\n})();\n```\n\nHere is an example that demonstrates how to use the store with the [node-cache-manager](https://github.com/jaredwray/cache-manager) module.\n\n```javascript\nconst cacheManager = require('cache-manager');\nconst { DiskStore } = require('cache-manager-fs-hash');\n\nconst diskCache = cacheManager.createCache(new DiskStore({\n    path: 'diskcache', // path for cached files\n    // ... other options\n}));\n\n\n(async () => {\n\n    await diskCache.set('key', 'value');\n    console.log(await diskCache.get('key')); // \"value\"\n\n    console.log(await getUserCached(5)); // {id: 5, name: '...'}\n    console.log(await getUserCached(5)); // {id: 5, name: '...'}\n\n    function getUserCached(userId) {\n        return diskCache.wrap(userId, function () {\n            return getUser(userId);\n        });\n    }\n\n    async function getUser(userId) {\n        await new Promise(r => setTimeout(r, 100)); // sleep 0.1 seconds\n        return {id: userId, name: '...' + Math.random()};\n    }\n\n})();\n```\n\n## How it works\n\nThe library saves each cached item as a separate file under the specified directory. Writes use a `.lock` file to ensure that multiple instances accessing the same cache file do not interfere with each other.\n\n## Tests\n\n```sh\nnpm test\n```\n\n## License\n\ncache-manager-fs-hash is licensed under the MIT license.\n","publish_time":1756566867150,"_cnpm_publish_time":1756566867150,"dist-tags":{"latest":"3.0.0"}}