{"id":15369117,"url":"https://github.com/developit/request-easy-cache","last_synced_at":"2025-06-13T21:06:47.753Z","repository":{"id":33502923,"uuid":"37148869","full_name":"developit/request-easy-cache","owner":"developit","description":":racehorse: A simple, configurable \u0026 instantiable caching wrapper around request.","archived":false,"fork":false,"pushed_at":"2017-05-17T06:32:00.000Z","size":29,"stargazers_count":11,"open_issues_count":7,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-11T16:02:12.786Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://npm.im/request-easy-cache","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/developit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-09T17:59:18.000Z","updated_at":"2023-09-25T07:41:50.000Z","dependencies_parsed_at":"2022-08-07T22:00:16.694Z","dependency_job_id":null,"html_url":"https://github.com/developit/request-easy-cache","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/developit/request-easy-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developit%2Frequest-easy-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developit%2Frequest-easy-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developit%2Frequest-easy-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developit%2Frequest-easy-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/developit","download_url":"https://codeload.github.com/developit/request-easy-cache/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developit%2Frequest-easy-cache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259719722,"owners_count":22901241,"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":[],"created_at":"2024-10-01T13:34:14.960Z","updated_at":"2025-06-13T21:06:47.725Z","avatar_url":"https://github.com/developit.png","language":"JavaScript","readme":"[![NPM version][npm-version-image]][npm-url] [![NPM downloads][npm-downloads-image]][npm-url] [![MIT License][license-image]][license-url] [![Build Status][travis-image]][travis-url]\n\n# request-easy-cache\n\n\u003e A caching wrapper around [request].\n\u003e\n\u003e `npm install --save request-easy-cache`\n\n`request-easy-cache` wraps calls to `request` in a layer that caches HTTP responses automatically. Multiple identical requests produce a cached `response` and `body`.\n\nCaching is done in-memory using [lru-cache], keyed on `{url,options}`. Calls with identical `url` and `options` return the same `response` and a cloned `body`.\n\n\n---\n\n\n## Usage\n\nProvided in ES6 for clarity.\n\n```js\nimport request from 'request-easy-cache';\n\nfunction get(callback) {\n\trequest.get('http://pokeapi.co/api/v1/pokemon/1', {\n\t\tjson: true\n\t}, (err, res, body) =\u003e {\n\t\tcallback(body);\n\t});\n}\n\n// simple test example\nget( body =\u003e {\n\n\tlet start = Date.now();\n\tget( body2 =\u003e {\n\t\tlet time = Date.now() - start;\n\n\t\tassert.ok(time\u003c10, 'Should be a cache hit (\u003c10ms)');\n\n\t\tassert.deepEqual(body, body2, 'Should return the same data for a cached call');\n\t});\n});\n```\n\n\n\u003e _**Note:** In addition to [request]'s options, `request-easy-cache` adds a `{boolean} cache` option that, when set to `false`, disables caching for the request._\n\n\n---\n\n\n## Methods\n\n\n##### `.get(url, callback)`\n\n\u003e Fetch a URL using the default options.\n\u003e\n\u003e Callback signature is identical to [request]'s: `(err, res, body)`.\n\n##### `.get(url, options, callback)`\n\n\u003e Fetch a URL with the specified options.\n\u003e\n\u003e Supports all [request] options.\n\n##### `.get(options, callback)`\n\n\u003e Fetch via the specified options.\n\u003e\n\u003e One of `options.url` or `options.uri` must be set.\n\u003e\n\u003e Supports all [request] options.\n\n\n---\n\n\n## Configuration\n\nThe default export is an instance of `RequestEasyCache` with all default options.\n\n* `max: 100`: Maximum number of responses to keep cached. Least-recently-used responses are dropped in favor of new ones.\n* `maxAge: 60000`: Maximum time to keep cached responses, in milliseconds. Defaults to 1 minute.\n\nYou can override the default settings:\n\n```js\nrequestEasyCache.enableCache({\n\tmax: 100,\t\t   // 100 cached responses\n\tmaxAge: 60000\t   // 60 seconds, in milliseconds\n});\n```\n\nIt is also possible to create customized instances of `RequestEasyCache`:\n\n```js\nimport { RequestEasyCache } from 'request-easy-cache';\n\nlet cachedRequest = new RequestEasyCache({\n\tcacheHttpErrors: false,\t\t// don't cache 4xx/5xx errors\n\tcache: {\n\t\tmax: 200,\t\t// max number of responses to keep\n\t\tmaxAge: 5*6e4\t// 5 minute cache lifetime\n\t}\n});\n\ncachedRequest.get('...', (err, res, body) =\u003e {});\n```\n\n\n## How It Works\n\nCaching uses a compound key `{ url, options }`. Calls with identical `url` and `options` return the same data.\n\n\n---\n\n\n## Version History\n\n* `1.3.0` - Passthrough support for non-`GET` requests, added `request(opts)` method.\n* `1.2.0` - Support time strings for `cache.maxAge` via [ms](https://www.npmjs.com/package/ms).\n* `1.1.1` - Added preferred support for `.get()`. `.cached()` is now an alias.\n* `1.1.0` - Updated to be simpler and more similar to the [request] API (retains backwards compatibility).\n* `1.0.0` - Forked from [request-again], rewritten in ES6.\n\n\n[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square\n[license-url]: https://github.com/developit/request-easy-cache/blob/master/LICENSE\n\n[npm-version-image]: http://img.shields.io/npm/v/request-easy-cache.svg?style=flat-square\n[npm-downloads-image]: http://img.shields.io/npm/dm/request-easy-cache.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/request-easy-cache\n\n[travis-image]: http://img.shields.io/travis/developit/request-easy-cache/master.svg?style=flat-square\n[travis-url]: http://travis-ci.org/developit/request-easy-cache\n\n[request]: https://www.npmjs.com/package/request\n[request-again]: https://github.com/hemphillcc/request-again\n[lru-cache]: https://www.npmjs.com/package/lru-cache\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevelopit%2Frequest-easy-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevelopit%2Frequest-easy-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevelopit%2Frequest-easy-cache/lists"}