{"name":"cache-point","author":{"name":"Lloyd Brookes","email":"75pound@gmail.com"},"version":"3.0.0","description":"Simple, filesystem-backed memoisation cache.","repository":{"type":"git","url":"git+https://github.com/75lb/cache-point.git"},"type":"module","exports":{"import":"./index.js","require":"./dist/index.cjs"},"keywords":["memoisation","memoization","cache","file","store"],"license":"MIT","engines":{"node":">=12.17"},"scripts":{"test":"npm run dist && npm run test:ci","test:ci":"75lb-nature test test/async.js test/sync.js","dist":"75lb-nature cjs-build index.js","docs":"75lb-nature jsdoc2md -t README.hbs index.js > README.md"},"dependencies":{"array-back":"^6.2.2"},"peerDependencies":{"@75lb/nature":"^0.1.1"},"peerDependenciesMeta":{"@75lb/nature":{"optional":true}},"standard":{"ignore":["tmp","dist"],"envs":[]},"_id":"cache-point@3.0.0","gitHead":"5f69633eefe07deab018e5e38b1622092b954906","bugs":{"url":"https://github.com/75lb/cache-point/issues"},"homepage":"https://github.com/75lb/cache-point#readme","_nodeVersion":"22.7.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-LDGNWYv/tqRWAAZxMy75PIYynaIuhcyoyjJtwA7X5uMZjdzvGm+XmTey/GXUy2EJ+lwc2eBFzFYxjvNYyE/0Iw==","shasum":"4d9035faae682414328334329cc18e1db7d0cf5d","tarball":"http://registry-npm.ywwl.com/cache-point/download/cache-point-3.0.0.tgz","fileCount":6,"unpackedSize":19219,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCkiHsMwxZXhSIwPY5/UvusapxNdUBFf4b0Tc8XoLQLqAIhANdkan2ULdBr/8jJtoyjz9Ce3Uhc2NMTi2A6pWYq77bc"}],"size":4403,"noattachment":false,"key":"/cache-point/-/cache-point-3.0.0.tgz"},"_npmUser":{"name":"75lb","email":"75pound@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cache-point_3.0.0_1724535259674_0.6533782689859993"},"_hasShrinkwrap":false,"readme":"[![view on npm](https://badgen.net/npm/v/cache-point)](https://www.npmjs.org/package/cache-point)\n[![npm module downloads](https://badgen.net/npm/dt/cache-point)](https://www.npmjs.org/package/cache-point)\n[![Gihub repo dependents](https://badgen.net/github/dependents-repo/75lb/cache-point)](https://github.com/75lb/cache-point/network/dependents?dependent_type=REPOSITORY)\n[![Gihub package dependents](https://badgen.net/github/dependents-pkg/75lb/cache-point)](https://github.com/75lb/cache-point/network/dependents?dependent_type=PACKAGE)\n[![Node.js CI](https://github.com/75lb/cache-point/actions/workflows/node.js.yml/badge.svg)](https://github.com/75lb/cache-point/actions/workflows/node.js.yml)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)\n\n# cache-point\n\nSimple, filesystem-backed memoisation cache. Use to cache the output of expensive operations speeding up future invocations with the same input.\n\n## Synopsis\n\n```js\nimport Cache from 'cache-point'\nimport { setTimeout as sleep } from 'node:timers/promises'\n\n/* mock function to simulate a slow, remote request */\nasync function fetchUser (id) {\n  await sleep(1000)\n  return { id, name: 'Layla' }\n}\n\nclass Users {\n  constructor () {\n    this.cache = new Cache({ dir: 'tmp/example' })\n  }\n\n  async getUser (id) {\n    let user\n    try {\n      /* cache.read() will resolve on hit, reject on miss */\n      user = await this.cache.read(id)\n    } catch (err) {\n      if (err.code === 'ENOENT') {\n        /* cache miss, fetch remote user */\n        user = await fetchUser(id)\n        this.cache.write(id, user)\n      }\n    }\n    return user\n  }\n}\n\nconsole.time('getUser')\nconst users = new Users()\nconst user = await users.getUser(10)\nconsole.timeEnd('getUser')\nconsole.log(user)\n```\n\nThe first invocation will take 1 second while the remote user is fetched.\n\n```\n$ node example/simple.js\ngetUser: 1.025s\n{ id: 10, name: 'Layla' }\n```\n\nSince the cache is now warm, future invocations will be fast.\n\n```\n$ node example/simple.js\ngetUser: 17.07ms\n{ id: 10, name: 'Layla' }\n```\n\n## API Reference\n\n<a name=\"module_cache-point\"></a>\n\n## cache-point\n\n* [cache-point](#module_cache-point)\n    * [Cache](#exp_module_cache-point--Cache) ⏏\n        * [new Cache([options])](#new_module_cache-point--Cache_new)\n        * [.dir](#module_cache-point--Cache+dir) : <code>string</code>\n        * [.read(keys)](#module_cache-point--Cache+read) ⇒ <code>Promise</code>\n        * [.readSync(keys)](#module_cache-point--Cache+readSync) ⇒ <code>string</code>\n        * [.write(keys, content)](#module_cache-point--Cache+write) ⇒ <code>Promise</code>\n        * [.writeSync(keys, content)](#module_cache-point--Cache+writeSync)\n        * [.getChecksum(keys)](#module_cache-point--Cache+getChecksum) ⇒ <code>string</code>\n        * [.clear()](#module_cache-point--Cache+clear) ⇒ <code>Promise</code>\n        * [.remove()](#module_cache-point--Cache+remove) ⇒ <code>Promise</code>\n\n<a name=\"exp_module_cache-point--Cache\"></a>\n\n### Cache ⏏\n**Kind**: Exported class  \n<a name=\"new_module_cache-point--Cache_new\"></a>\n\n#### new Cache([options])\n\n| Param | Type |\n| --- | --- |\n| [options] | <code>object</code> | \n| [options.dir] | <code>string</code> | \n\n<a name=\"module_cache-point--Cache+dir\"></a>\n\n#### cache.dir : <code>string</code>\nCurrent cache directory. Can be changed at any time.\n\n**Kind**: instance property of [<code>Cache</code>](#exp_module_cache-point--Cache)  \n<a name=\"module_cache-point--Cache+read\"></a>\n\n#### cache.read(keys) ⇒ <code>Promise</code>\nA cache hit resolves with the stored value, a miss rejects with an `ENOENT` error code.\n\n**Kind**: instance method of [<code>Cache</code>](#exp_module_cache-point--Cache)  \n**Throws**:\n\n- ENOENT\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| keys | <code>\\*</code> | One or more values to uniquely identify the data. Can be any value, or an array of values of any type. |\n\n<a name=\"module_cache-point--Cache+readSync\"></a>\n\n#### cache.readSync(keys) ⇒ <code>string</code>\nA cache hit returns the stored value, a miss returns `null`.\n\n**Kind**: instance method of [<code>Cache</code>](#exp_module_cache-point--Cache)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| keys | <code>\\*</code> | One or more values to uniquely identify the data. Can be any value, or an array of values of any type. |\n\n<a name=\"module_cache-point--Cache+write\"></a>\n\n#### cache.write(keys, content) ⇒ <code>Promise</code>\nWrite some data to the cache. Returns a promise which resolves when the write is complete.\n\n**Kind**: instance method of [<code>Cache</code>](#exp_module_cache-point--Cache)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| keys | <code>\\*</code> | One or more values to index the data, e.g. a request object or set of function args. |\n| content | <code>\\*</code> | the data to store |\n\n<a name=\"module_cache-point--Cache+writeSync\"></a>\n\n#### cache.writeSync(keys, content)\nWrite some data to the cache with a key.\n\n**Kind**: instance method of [<code>Cache</code>](#exp_module_cache-point--Cache)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| keys | <code>\\*</code> | One or more values to index the data, e.g. a request object or set of function args. |\n| content | <code>\\*</code> | the data to store |\n\n<a name=\"module_cache-point--Cache+getChecksum\"></a>\n\n#### cache.getChecksum(keys) ⇒ <code>string</code>\nUsed internally to convert a key value into a hex checksum. Override if for some reason you need a different hashing strategy.\n\n**Kind**: instance method of [<code>Cache</code>](#exp_module_cache-point--Cache)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| keys | <code>\\*</code> | One or more values to index the data, e.g. a request object or set of function args. |\n\n<a name=\"module_cache-point--Cache+clear\"></a>\n\n#### cache.clear() ⇒ <code>Promise</code>\nClears the cache. Returns a promise which resolves once the cache is clear.\n\n**Kind**: instance method of [<code>Cache</code>](#exp_module_cache-point--Cache)  \n<a name=\"module_cache-point--Cache+remove\"></a>\n\n#### cache.remove() ⇒ <code>Promise</code>\nClears and removes the cache directory. Returns a promise which resolves once the remove is complete.\n\n**Kind**: instance method of [<code>Cache</code>](#exp_module_cache-point--Cache)  \n\n* * *\n\n&copy; 2016-24 Lloyd Brookes \\<75pound@gmail.com\\>.\n\nTested by [test-runner](https://github.com/test-runner-js/test-runner). Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).\n","publish_time":1724535259814,"maintainers":[{"name":"75lb","email":"75pound@gmail.com"}],"_cnpm_publish_time":1724535259814,"dist-tags":{"latest":"3.0.1"}}