{"_id":"p-async-cache","_rev":"6-718bb549211cf069cbb6fdb0b4542470","name":"p-async-cache","dist-tags":{"latest":"1.0.3"},"versions":{"0.0.0":{"name":"p-async-cache","version":"0.0.0","description":"","main":"index.js","scripts":{},"license":"MIT","_id":"p-async-cache@0.0.0","_shasum":"92df88851f2cf8118c39709f5e5d1e71f17e89be","_from":".","_npmVersion":"4.1.2","_nodeVersion":"7.7.1","_npmUser":{"name":"kael","email":"i@kael.me"},"maintainers":[{"name":"kael","email":"i@kael.me"}],"dist":{"shasum":"92df88851f2cf8118c39709f5e5d1e71f17e89be","tarball":"https://registry.npmjs.org/p-async-cache/-/p-async-cache-0.0.0.tgz","integrity":"sha512-FYFnvgE0L8MgCu7hyzddNu36ABSa96CzJpQAxCGvIGYwda4C23g8OPcowuYIbLwp2ppz2oI8tAy41r8Qou59/Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICtgWeSh1TRohspCsrrEu9nVyK3gmzTuzEwz1sT9I8ClAiArkoZgItkrviq2zYYcpcwo8onEL5u6ATT7dXRMuiulrw=="}]},"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/p-async-cache-0.0.0.tgz_1488874860684_0.5801277798600495"}},"1.0.0":{"name":"p-async-cache","version":"1.0.0","description":"Cache the promise lookups and avoid fetching the same thing more than necessary","main":"index.js","scripts":{"build":"babel src --out-dir lib","test":"npm run build && node --harmony ./node_modules/.bin/ava --verbose --timeout=10s","prepublish":"npm run build"},"repository":{"type":"git","url":"git://github.com/kaelzhang/p-async-cache.git"},"keywords":["p-async-cache","promise","async","cache","lru-cache"],"engines":{"node":">=4"},"author":{"name":"kaelzhang"},"license":"MIT","bugs":{"url":"https://github.com/kaelzhang/p-async-cache/issues"},"ava":{"require":"babel-register","babel":{"babelrc":true}},"devDependencies":{"ava":"^0.16.0","babel-cli":"^6.16.0","babel-plugin-syntax-trailing-function-commas":"^6.13.0","babel-plugin-transform-class-properties":"^6.16.0","babel-plugin-transform-es2015-modules-commonjs":"^6.16.0","babel-plugin-transform-exponentiation-operator":"^6.8.0","babel-plugin-transform-inline-environment-variables":"^6.8.0","babel-plugin-transform-object-rest-spread":"^6.16.0","babel-preset-es2015":"^6.16.0","delay":"^1.3.1"},"dependencies":{"lru-cache":"^4.0.2","pending-queue":"^1.2.0"},"gitHead":"a5bc1d52fb146b714e2681843706ff2b7a70d176","homepage":"https://github.com/kaelzhang/p-async-cache#readme","_id":"p-async-cache@1.0.0","_shasum":"4b4519b74177a5f8d024d33c63a250d84bf9eebb","_from":".","_npmVersion":"4.1.2","_nodeVersion":"7.7.1","_npmUser":{"name":"kael","email":"i@kael.me"},"maintainers":[{"name":"kael","email":"i@kael.me"}],"dist":{"shasum":"4b4519b74177a5f8d024d33c63a250d84bf9eebb","tarball":"https://registry.npmjs.org/p-async-cache/-/p-async-cache-1.0.0.tgz","integrity":"sha512-SRia1OQBWWV+1vVbcJIE7+K2rZFmh4vsDEhwsknM9IspAzVWsPnYkWHuuSIFtXwA2Q07In73YzC222inncAcDg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDtwwqH6WjJIGtUbK2/9jSLdLjvX6v1+SAvzizp13XxYAIgEBi0CqaEQONkvYqV5quLtgqzhCJ2OTA5e0+Wt6QyWTs="}]},"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/p-async-cache-1.0.0.tgz_1489026306492_0.5100951127242297"}},"1.0.2":{"name":"p-async-cache","version":"1.0.2","description":"Cache the promise lookups and avoid fetching the same thing more than necessary","main":"index.js","scripts":{"build":"babel src --out-dir lib","test":"npm run build && node --harmony ./node_modules/.bin/ava --verbose --timeout=10s","prepublish":"npm run build"},"repository":{"type":"git","url":"git://github.com/kaelzhang/p-async-cache.git"},"keywords":["p-async-cache","promise","async","cache","lru-cache"],"engines":{"node":">=4"},"author":{"name":"kaelzhang"},"license":"MIT","bugs":{"url":"https://github.com/kaelzhang/p-async-cache/issues"},"ava":{"require":"babel-register","babel":{"babelrc":true}},"devDependencies":{"ava":"^0.16.0","babel-cli":"^6.16.0","babel-plugin-syntax-trailing-function-commas":"^6.13.0","babel-plugin-transform-class-properties":"^6.16.0","babel-plugin-transform-es2015-modules-commonjs":"^6.16.0","babel-plugin-transform-exponentiation-operator":"^6.8.0","babel-plugin-transform-inline-environment-variables":"^6.8.0","babel-plugin-transform-object-rest-spread":"^6.16.0","babel-preset-es2015":"^6.16.0","delay":"^1.3.1"},"dependencies":{"lru-cache":"^4.0.2","pending-queue":"^1.2.0"},"gitHead":"65385a9abc2cda540a3baaac1990579722c2285c","homepage":"https://github.com/kaelzhang/p-async-cache#readme","_id":"p-async-cache@1.0.2","_shasum":"e8ad75dcaa09af7126ac2941eb31eaed18b33c1f","_from":".","_npmVersion":"4.1.2","_nodeVersion":"7.7.1","_npmUser":{"name":"kael","email":"i@kael.me"},"maintainers":[{"name":"kael","email":"i@kael.me"}],"dist":{"shasum":"e8ad75dcaa09af7126ac2941eb31eaed18b33c1f","tarball":"https://registry.npmjs.org/p-async-cache/-/p-async-cache-1.0.2.tgz","integrity":"sha512-c94aU4owlRzqwfIHnCTU+Mu49xqBy8KyUOxQyLDjEfoFFCLJzICRl7Di/JSVNF1N9mrweNs38NghkYQad0oe4A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFDV4Di7AukUKG/C/ifImZ7qSzZuGAIpCQ1uqJyBrNwFAiEAj5lDqH+I5UKXDogWXmyXP9fXNlfiGRIuOhKwzabXMPY="}]},"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/p-async-cache-1.0.2.tgz_1489041978408_0.5759908973705024"}},"1.0.3":{"name":"p-async-cache","version":"1.0.3","description":"Cache the promise lookups and avoid fetching the same thing more than necessary","main":"index.js","scripts":{"build":"babel src --out-dir lib","test":"npm run build && node --harmony ./node_modules/.bin/ava --verbose --timeout=10s","prepublish":"npm run build"},"repository":{"type":"git","url":"git://github.com/kaelzhang/p-async-cache.git"},"keywords":["p-async-cache","promise","async","cache","lru-cache"],"engines":{"node":">=4"},"author":{"name":"kaelzhang"},"license":"MIT","bugs":{"url":"https://github.com/kaelzhang/p-async-cache/issues"},"ava":{"require":"babel-register","babel":{"babelrc":true}},"devDependencies":{"ava":"^0.16.0","babel-cli":"^6.16.0","babel-plugin-syntax-trailing-function-commas":"^6.13.0","babel-plugin-transform-class-properties":"^6.16.0","babel-plugin-transform-es2015-modules-commonjs":"^6.16.0","babel-plugin-transform-exponentiation-operator":"^6.8.0","babel-plugin-transform-inline-environment-variables":"^6.8.0","babel-plugin-transform-object-rest-spread":"^6.16.0","babel-preset-es2015":"^6.16.0","delay":"^1.3.1"},"dependencies":{"lru-cache":"^4.0.2","pending-queue":"^1.2.0"},"gitHead":"6f0900a357f410d967c9f002edbada8d04ac8bc5","homepage":"https://github.com/kaelzhang/p-async-cache#readme","_id":"p-async-cache@1.0.3","_npmVersion":"5.5.1","_nodeVersion":"9.2.0","_npmUser":{"name":"kael","email":"i@kael.me"},"dist":{"integrity":"sha512-Fpre97gnVHbjXRLLn0fQx4Z0adpKYCOanNn04s4hAAakvTbb78AHKdSjrBIiUX1eP92bxWGzdUyeQ3A6UCU9Fw==","shasum":"b3b6da368b01c335f2ad8c0a648536329b648a48","tarball":"https://registry.npmjs.org/p-async-cache/-/p-async-cache-1.0.3.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDFj84CE/NpFfXyQKGe9/AQi3Y4kDWbd8Kqx+9OCj4AAgIgJJdB3Ukh2m2gxCvGlZgJ15TXjn3gld4x6qzKo2Bim9M="}]},"maintainers":[{"name":"kael","email":"i@kael.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-async-cache-1.0.3.tgz_1511763054705_0.9373961265664548"}}},"readme":"[![Build Status](https://travis-ci.org/kaelzhang/p-async-cache.svg?branch=master)](https://travis-ci.org/kaelzhang/p-async-cache)\n<!-- optional appveyor tst\n[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/p-async-cache?branch=master&svg=true)](https://ci.appveyor.com/project/kaelzhang/p-async-cache)\n-->\n<!-- optional npm version\n[![NPM version](https://badge.fury.io/js/p-async-cache.svg)](http://badge.fury.io/js/p-async-cache)\n-->\n<!-- optional npm downloads\n[![npm module downloads per month](http://img.shields.io/npm/dm/p-async-cache.svg)](https://www.npmjs.org/package/p-async-cache)\n-->\n<!-- optional dependency status\n[![Dependency Status](https://david-dm.org/kaelzhang/p-async-cache.svg)](https://david-dm.org/kaelzhang/p-async-cache)\n-->\n\n# p-async-cache\n\nCache the promise lookups and avoid fetching the same thing more than necessary.\n\n## Install\n\n```sh\n$ npm install p-async-cache --save\n```\n\n## Usage\n\n```js\nimport PAC from 'p-async-cache'\n\nlet counter = 0\nconst cache = new PAC({\n  async load (userId) {\n    counter ++\n    return await getUserFromRemote(userId)\n  }\n})\n\nfunction get () {\n  cache.get(123).then(({value}) => {\n    console.log(value, counter)\n  })\n}\n\nget()\nget()\n\n// [object User] 1\n// [object User] 1 (The counter still be 1)\n```\n\n## new AC(options)\n\n- **options** `Object=`\n  - stale `Boolean` whether allow stale value\n  - stringify `function()=JSON.stringify` method to serialize the `params` to a cache key.\n  - load `AsyncFunction(...params)|function(...params):Promise|function(...params)` accepts a normal synchronous function, a function that returns a promise, or an async function, and the `params` will be the parameters of the `.get(...params)` method.\n  - other options that [lru-cache](https://www.npmjs.com/package/lru-cache) supports\n\n### Example for `options.stale`\n\n```js\nimport delay from 'delay'\n\nconst cache = new AC({\n  stale: true,\n  maxAge: 100,\n  load (a, b) {\n    return delay(1).then(() => a + b)\n  }\n})\n\ncache.get(1, 2)\n.then(({value, stale}) => {\n  console.log(value)      // 3\n  console.log(stale)      // false\n\n  // Delay a timespan which is bigger than `maxAge`\n  return delay(101).then(() => cache.get(1, 2))\n})\n.then(({value, stale}) => {\n  console.log(value)      // 3\n  console.log(stale)      // true (the value is stale)\n\n  return delay(10).then(() => cache.get(1, 2))\n})\n.then(({value, stale}) => {\n  console.log(value)      // 3\n  console.log(stale)      // false (if the value is found as stale, it will refresh the value in the background)\n})\n```\n\n## .get(...params)\n\n- **params** `any` that will be passed into `options.load(...params)`\n\nReturns `Promise`\n\nLookup the value in the cache,\n\n- if found, then return.\n- if not found,\n  - if allow stale values, and the value is stale, then return the value, and refresh value in background.\n  - otherwise, load the value with `load(...params)`\n\n## Other methods of `lru-cache`\n\n- `.reset()`\n- `.has(...params)`\n- `.peek(...params)`\n- `.del(...params)`\n\n## License\n\nMIT\n","maintainers":[{"name":"kael","email":"i@kael.me"}],"time":{"modified":"2022-06-23T05:42:13.012Z","created":"2017-03-07T08:21:02.494Z","0.0.0":"2017-03-07T08:21:02.494Z","1.0.0":"2017-03-09T02:25:08.513Z","1.0.2":"2017-03-09T06:46:20.201Z","1.0.3":"2017-11-27T06:10:54.785Z"},"license":"MIT","readmeFilename":"README.md","description":"Cache the promise lookups and avoid fetching the same thing more than necessary","homepage":"https://github.com/kaelzhang/p-async-cache#readme","keywords":["p-async-cache","promise","async","cache","lru-cache"],"repository":{"type":"git","url":"git://github.com/kaelzhang/p-async-cache.git"},"author":{"name":"kaelzhang"},"bugs":{"url":"https://github.com/kaelzhang/p-async-cache/issues"}}