{"name":"cache-point","author":{"name":"Lloyd Brookes","email":"75pound@gmail.com"},"version":"2.0.0","description":"Simple, filesystem-backed memoisation cache.","repository":{"type":"git","url":"git+https://github.com/75lb/cache-point.git"},"license":"MIT","keywords":["memoisation","memoization","cache","file","store"],"engines":{"node":">=8"},"scripts":{"test":"test-runner test/*.js","docs":"jsdoc2md -t README.hbs index.js > README.md"},"devDependencies":{"jsdoc-to-markdown":"^5.0.3","test-runner":"~0.8.7"},"dependencies":{"array-back":"^4.0.1","fs-then-native":"^2.0.0","mkdirp2":"^1.0.4"},"gitHead":"438eefe196ad9d8c7687e1c774c51245c2551a96","bugs":{"url":"https://github.com/75lb/cache-point/issues"},"homepage":"https://github.com/75lb/cache-point#readme","_id":"cache-point@2.0.0","_nodeVersion":"13.2.0","_npmVersion":"6.13.1","dist":{"integrity":"sha512-4gkeHlFpSKgm3vm2gJN5sPqfmijYRFYCQ6tv5cLw0xVmT6r1z1vd4FNnpuOREco3cBs1G709sZ72LdgddKvL5w==","shasum":"91e03c38da9cfba9d95ac6a34d24cfe6eff8920f","tarball":"http://registry-npm.ywwl.com/cache-point/download/cache-point-2.0.0.tgz","fileCount":5,"unpackedSize":13841,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJd5rZACRA9TVsSAnZWagAAaCsP/i/3m9iN4DHvdGtl90/+\nZ63kTZzl94EgVVTrqIsbVaAmS8X+zLPfPgnx3DbiF2slJ1v7J5DNTHec+2I3\nmTbSl55QtjJJoQZ/FUpX7+4gNtiMVOV5ScpBDSbNIlpeLk9uDAD1CZFuFxw1\nrlqbyk2lM7FP+/fmGAwlrOMaotHaKRQ/P6OxjHnX1yBgB/nsyU6spvhKO/bk\njVCg62qc56a9xiqDaapfDdlSoRq93o6N4rFz+uH3PygYsNNyyE+GclGRaQZb\nFdwFLhyQpfuYIKCBY+eynKDRYACZIB+CWVVvvig4EPa0lqL7UzrqP/q7QobV\n54TEAqJGzEKuXEoIgkP6ohorrVg99dc3WSIKaPG06UJ/kDZ08e9r7g8spam4\nYrNpnP55X3GtRvqZyYlrG9uFNH/gIL5pJ7oNG16fMt/QALDfw1k00FImOOhI\ntTswFX8B8aJyniKZ8U6fXHUwUR+7RYNqjTNBOkv3Z8zykYGBAB/2vUvI1vpy\nYmuWzVlC1vx69T4HFtEbTHaRpod2yob3afp66GNLIy2HCJ36kr8dRafinqJz\nAjQtqvKvIK4qdLPUskfiZQJi9U67BpXsRHkeIbvqeAwocnqrySpya8sQR1DS\nbSuISicBFhKGdiTL2mHCTn4LyFrelcbjC6VcjSh/fqzSKFmzdJUhHYl1NWrD\n2Sar\r\n=HH1O\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDeiQP6l0hSVejnWn/q+sY6CJCmYwf0Q5Y57SLz1T7glQIgBiCYgmLULT83U5owosvuH7tVh6T7Q4zmVFYeSDkaZZQ="}],"size":3641,"noattachment":false,"key":"/cache-point/-/cache-point-2.0.0.tgz"},"maintainers":[{"name":"75lb","email":"75pound@gmail.com"}],"_npmUser":{"name":"75lb","email":"75pound@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/cache-point_2.0.0_1575401023986_0.5509894689603325"},"_hasShrinkwrap":false,"readme":"[![view on npm](http://img.shields.io/npm/v/cache-point.svg)](https://www.npmjs.org/package/cache-point)\n[![npm module downloads](http://img.shields.io/npm/dt/cache-point.svg)](https://www.npmjs.org/package/cache-point)\n[![Build Status](https://travis-ci.org/75lb/cache-point.svg?branch=master)](https://travis-ci.org/75lb/cache-point)\n[![Dependency Status](https://badgen.net/david/dep/75lb/cache-point)](https://david-dm.org/75lb/cache-point)\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\nconst Cache = require('cache-point')\n\n/* a mock function to simulate a slow remote request */\nasync function fetchUser (id) {\n  return new Promise(resolve => {\n    setTimeout(() => {\n      resolve({ id, name: 'Layla' })\n    }, 1000)\n  })\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\nasync function start () {\n  console.time('getUser')\n  const users = new Users()\n  const user = await users.getUser(1)\n  console.timeEnd('getUser')\n  console.log(user)\n}\n\nstart().catch(console.error)\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-20 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":1575401024078,"_cnpm_publish_time":1575401024078,"dist-tags":{"latest":"3.0.1"}}