{"name":"cache-point","author":{"name":"Lloyd Brookes","email":"75pound@gmail.com"},"version":"0.2.0","description":"cache-point","repository":{"type":"git","url":"git+https://github.com/75lb/cache-point.git"},"license":"MIT","main":"index","keywords":[],"engines":{"node":">=0.10.0"},"scripts":{"test":"tape test/*.js","docs":"jsdoc2md -t jsdoc2md/README.hbs lib/*.js > README.md; echo","es5":"babel --presets babel-preset-es2015 --no-comments lib --out-dir es5"},"devDependencies":{"tape":"^4.6.0"},"dependencies":{"array-back":"^1.0.3","babel-preset-es2015":"^6.9.0","core-js":"^2.4.1","feature-detect-es6":"^1.3.1","mkdirp":"~0.5.1"},"gitHead":"aa3e7917e936564c07c725b485ea71bb37aae23c","bugs":{"url":"https://github.com/75lb/cache-point/issues"},"homepage":"https://github.com/75lb/cache-point#readme","_id":"cache-point@0.2.0","_shasum":"bf842a0f15bb53fae2dd5850df0b770c9a591e2f","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.3.1","_npmUser":{"name":"75lb","email":"75pound@gmail.com"},"dist":{"shasum":"bf842a0f15bb53fae2dd5850df0b770c9a591e2f","tarball":"http://registry-npm.ywwl.com/cache-point/download/cache-point-0.2.0.tgz","integrity":"sha512-pIaswpj/7bZjPnXdExwwGRRhse8QvOaeORYSXtYoSVb0OAY2VV1uZB86XeNbrmMhflSQTZK0O82XBGQTw8qRuQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDYH5afdw146nUNeBZ2/sIFjJCrkbK7TaBxSEuCG7FheAIgDju2kJpiG9cL16N4/so/L1JZr7TUk8Dju6I4/6KAo7Y="}],"size":4181,"noattachment":false,"key":"/cache-point/-/cache-point-0.2.0.tgz"},"maintainers":[{"name":"75lb","email":"75pound@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/cache-point-0.2.0.tgz_1469832397210_0.8601959818042815"},"directories":{},"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":1469832400185,"_cnpm_publish_time":1469832400185,"dist-tags":{"latest":"3.0.1"}}