{"id":15657438,"url":"https://github.com/transitive-bullshit/p-cache","last_synced_at":"2025-06-15T03:02:25.570Z","repository":{"id":57317385,"uuid":"98588240","full_name":"transitive-bullshit/p-cache","owner":"transitive-bullshit","description":"Decorator to memoize the results of async functions via lru-cache.","archived":false,"fork":false,"pushed_at":"2020-07-11T23:12:59.000Z","size":38,"stargazers_count":24,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-02T21:07:17.029Z","etag":null,"topics":["async","cache","memoize","memoize-decorator","promise"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/transitive-bullshit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-27T23:43:26.000Z","updated_at":"2025-05-02T14:14:28.000Z","dependencies_parsed_at":"2022-08-25T21:11:53.277Z","dependency_job_id":null,"html_url":"https://github.com/transitive-bullshit/p-cache","commit_stats":null,"previous_names":["fisch0920/p-cache"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/transitive-bullshit/p-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transitive-bullshit%2Fp-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transitive-bullshit%2Fp-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transitive-bullshit%2Fp-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transitive-bullshit%2Fp-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/transitive-bullshit","download_url":"https://codeload.github.com/transitive-bullshit/p-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transitive-bullshit%2Fp-cache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259914868,"owners_count":22931323,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","cache","memoize","memoize-decorator","promise"],"created_at":"2024-10-03T13:07:03.713Z","updated_at":"2025-06-15T03:02:25.539Z","avatar_url":"https://github.com/transitive-bullshit.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# p-cache\n\n\u003e Decorator to memoize the results of async functions via lru-cache.\n\n[![NPM](https://img.shields.io/npm/v/p-cache.svg)](https://www.npmjs.com/package/p-cache) [![Build Status](https://travis-ci.com/transitive-bullshit/p-cache.svg?branch=master)](https://travis-ci.com/transitive-bullshit/p-cache) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n## Features\n\n- Uses [lru-cache](https://www.npmjs.com/package/lru-cache) for caching impl\n- Uses [object-hash](https://www.npmjs.com/package/hash-object) for implicit cache key derivation from function args\n- Thoroughly tested in production\n\n## Install\n\n```bash\nnpm install --save p-cache\n```\n\n## Usage\n\n```js\nconst request = require('request-promise-native')\n\nconst pCache = require('p-cache')({\n  label: 'test-service',\n  // pass args to lru-cache here\n  max: 1000\n})\n\n// returns an async function which gets the given url, with the results being \n// cached via lru-cache up to 1000 urls\nmodule.exports = pCache(async (url) =\u003e {\n  return request(url)\n})\n```\n\n## API\n\n### function pCache(opts)\n\nReturns a function decorator that will wrap calls to the target function in an lru-cache instance defined by these `opts`.\n\n- `opts` - object, optional\n- `opts.label` - string, optional label to use for displaying cache hits and misses\n- `opts.log` - function, optional function to use for displaying cache hits and misses (default: `console.log`)\n\n*Note* all unrecognized options are passed onto [lru-cache](https://github.com/isaacs/node-lru-cache)\n- `opts.max` - number, optional passed onto [lru-cache](https://github.com/isaacs/node-lru-cache)\n- `opts.maxAge` - number, optional passed onto [lru-cache](https://github.com/isaacs/node-lru-cache)\n- `opts.length` - function, optional passed onto [lru-cache](https://github.com/isaacs/node-lru-cache)\n- `opts.dispose` - function, optional passed onto [lru-cache](https://github.com/isaacs/node-lru-cache)\n- `opts.stale` - boolean, optional passed onto [lru-cache](https://github.com/isaacs/node-lru-cache)\n- `opts.noDisposeOnSet` - boolean, optional passed onto [lru-cache](https://github.com/isaacs/node-lru-cache)\n\n`pCache(opts) =\u003e Function\u003cPromise\u003e(async function(...args))`\n\n## License\n\nMIT © [Travis Fischer](https://github.com/fisch0920)\n\nSupport my OSS work by \u003ca href=\"https://twitter.com/transitive_bs\"\u003efollowing me on twitter \u003cimg src=\"https://storage.googleapis.com/saasify-assets/twitter-logo.svg\" alt=\"twitter\" height=\"24px\" align=\"center\"\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftransitive-bullshit%2Fp-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftransitive-bullshit%2Fp-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftransitive-bullshit%2Fp-cache/lists"}