{"_id":"@kikobeats/cacheable-request","_rev":"5-27901482e3c0868d60126f27a680649e","name":"@kikobeats/cacheable-request","dist-tags":{"latest":"7.0.7"},"versions":{"7.0.3":{"name":"@kikobeats/cacheable-request","version":"7.0.3","keywords":["HTTP","HTTPS","cache","caching","layer","cacheable","RFC 7234","RFC","7234","compliant"],"author":{"url":"http://lukechilds.co.uk","name":"Luke Childs","email":"lukechilds123@gmail.com"},"license":"MIT","_id":"@kikobeats/cacheable-request@7.0.3","maintainers":[{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"}],"homepage":"https://github.com/lukechilds/cacheable-request#readme","bugs":{"url":"https://github.com/lukechilds/cacheable-request/issues"},"xo":{"extends":"xo-lukechilds"},"dist":{"shasum":"0650700cbda4b935c6d4db539385560ab83a0a57","tarball":"https://registry.npmjs.org/@kikobeats/cacheable-request/-/cacheable-request-7.0.3.tgz","fileCount":4,"integrity":"sha512-RCc9sX44EHIAFPnv4aQwz0YYs/Ews4deioQHCTBe6nxz/x4SICTmhAE7rtkA9xgAy5MlJPuNb92fsm7Dd/aK7g==","signatures":[{"sig":"MEYCIQCWmsg2GKkIOneHX0Fh47tx0Cu9GuP8YxSAQFPjeFDHaAIhANUfRpm6GeX3KZEWVy/nGJSt+UjPlzDPMVPDfmXi5225","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":16929,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkPaaVACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpZkxAAjzYWEm2ZytxUMOKqGIfS+b+aPTKq/sG3ItMsOSzazKOBS4K6\r\nyOgoYEs4T5lDlEc/x1iYxWj5lFB4HZhBP9+cq4EXCVr3FtCqZoA6siC724ru\r\nxHJpeHlcNZLMXZtzKNYECMgh3bx9EdFcfTv9+VOKbb09RQIAJLhcT8TbO9kK\r\nvenc7DJe7r7dC0VJMaTo/6wzfQSf9NTVdgJZKybPxzsmc+q4plqhOi6YGWK6\r\nqtePLCMHj1ZRsjERtBXb34E/mpQlbbP6CyQ0xlVzEtxMidnHcxr/tXKvti6T\r\nS2n0ddOCrJrh49l3EcDMktZ6nnLAS1jUGqo/sM3ZmVGx7+9P3VG8doYJwvtV\r\nuaPfQjAONrfWC22tHQh6gLtg8CkT4u01B9rzTbmPmlj1aCrSNxIai0ohBnR7\r\nRruOaJFdCAlZtK1ttee55qfAxG7w54l1Ln2pELsCcRlcNXSxEsSkKQQtdaGn\r\nPpnj+iGDPij3C9doSUu56uBsDMRhR5BOqjg3NN5OkAXUsCeBMooFbeyH/tRh\r\nBDkOSmcJlgt1M7dzzomUcjH6w2HQCK5PVvKrsS8fr0SklqRVm3Ups0qhPcOo\r\nnoyOigHP2bgCQXubYwIfCV7tI4YX7aBn3Mg6/C8JdLMP7PD8CvYzXV9OHuSJ\r\n14zij98P/OTwI0TcTP497HDMOioQ8nWOZfs=\r\n=3yzM\r\n-----END PGP SIGNATURE-----\r\n"},"main":"src/index.js","_from":"file:kikobeats-cacheable-request-7.0.3.tgz","engines":{"node":">=8"},"scripts":{"test":"xo && nyc ava","coverage":"nyc report --reporter=text-lcov | coveralls"},"_npmUser":{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"},"_resolved":"/private/var/folders/wl/c4tw_5s97c9b26n2cj99x4180000gn/T/555e3bd086b4034e5003ad499e0fd448/kikobeats-cacheable-request-7.0.3.tgz","_integrity":"sha512-RCc9sX44EHIAFPnv4aQwz0YYs/Ews4deioQHCTBe6nxz/x4SICTmhAE7rtkA9xgAy5MlJPuNb92fsm7Dd/aK7g==","repository":{"url":"git+https://github.com/lukechilds/cacheable-request.git","type":"git"},"_npmVersion":"9.5.0","description":"Wrap native HTTP requests with RFC compliant cache support","directories":{},"_nodeVersion":"18.15.0","dependencies":{"keyv":"^4.0.0","get-stream":"^5.1.0","responselike":"^2.0.0","normalize-url":"^6.0.1","clone-response":"^1.0.2","lowercase-keys":"^2.0.0","http-cache-semantics":"^4.0.0"},"_hasShrinkwrap":false,"devDependencies":{"xo":"^0.23.0","ava":"^1.1.0","nyc":"^14.1.1","pify":"^4.0.0","this":"^1.0.2","delay":"^4.0.0","sqlite3":"^4.0.2","coveralls":"^3.0.0","@keyv/sqlite":"^2.0.0","create-test-server":"3.0.0","eslint-config-xo-lukechilds":"^1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/cacheable-request_7.0.3_1681761941126_0.7910951255448224","host":"s3://npm-registry-packages"}},"7.0.4":{"name":"@kikobeats/cacheable-request","version":"7.0.4","keywords":["7234","HTTP","HTTPS","RFC","RFC 7234","cache","cacheable","caching","compliant","layer"],"author":{"url":"https://kikobeats.com","name":"Kiko Beats","email":"josefrancisco.verdu@gmail.com"},"license":"MIT","_id":"@kikobeats/cacheable-request@7.0.4","maintainers":[{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"}],"homepage":"https://github.com/@kikobeats/cacheable-request#readme","bugs":{"url":"https://github.com/@kikobeats/cacheable-request/issues"},"dist":{"shasum":"a03a292f0fed92a2d4b769d63e678c40bf492633","tarball":"https://registry.npmjs.org/@kikobeats/cacheable-request/-/cacheable-request-7.0.4.tgz","fileCount":4,"integrity":"sha512-Woewio0qQbjhfhi35xx/kfv4bOwiFr9jEkD2G3szx+C2SM1G8hHIVXUMAztaWGbizngQ5ov9MpH9KRt0NUTAKA==","signatures":[{"sig":"MEUCIQCJNG7pmVAJpy10vga9jt2w82BjuUEFD6OFTBURssTs5QIgW6IvF0luzUjtBq4Kd8l+bHhXE+F6a6BkgVqxVSxim+s=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":18456},"jest":{"testMatch":["**/test/**/*.js"],"testEnvironment":"node","moduleFileExtensions":["js"]},"main":"src/index.js","_from":"file:kikobeats-cacheable-request-7.0.4.tgz","engines":{"node":">=18"},"scripts":{"test":"c8 jest"},"_npmUser":{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"},"_resolved":"/private/var/folders/wl/c4tw_5s97c9b26n2cj99x4180000gn/T/08288db27036de2af67f1f372ef3a292/kikobeats-cacheable-request-7.0.4.tgz","_integrity":"sha512-Woewio0qQbjhfhi35xx/kfv4bOwiFr9jEkD2G3szx+C2SM1G8hHIVXUMAztaWGbizngQ5ov9MpH9KRt0NUTAKA==","repository":{"url":"git+https://github.com/@kikobeats/cacheable-request.git","type":"git"},"_npmVersion":"10.5.2","description":"Wrap native HTTP requests with RFC compliant cache support","directories":{},"_nodeVersion":"20.13.0","dependencies":{"keyv":"^4.5.4","responselike":"^2.0.0","normalize-url":"^6.0.3","http-cache-semantics":"^4.1.1"},"_hasShrinkwrap":false,"devDependencies":{"c8":"latest","jest":"latest","sqlite3":"latest","standard":"latest","get-stream":"5","@keyv/sqlite":"latest","create-test-server":"latest"},"_npmOperationalInternal":{"tmp":"tmp/cacheable-request_7.0.4_1715426307201_0.43408993910018134","host":"s3://npm-registry-packages"}},"7.0.5":{"name":"@kikobeats/cacheable-request","version":"7.0.5","keywords":["7234","HTTP","HTTPS","RFC","RFC 7234","cache","cacheable","caching","compliant","layer"],"author":{"url":"https://kikobeats.com","name":"Kiko Beats","email":"josefrancisco.verdu@gmail.com"},"license":"MIT","_id":"@kikobeats/cacheable-request@7.0.5","maintainers":[{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"}],"homepage":"https://github.com/@kikobeats/cacheable-request#readme","bugs":{"url":"https://github.com/@kikobeats/cacheable-request/issues"},"dist":{"shasum":"9b7afc1ef444317e2991dfb732c5015b081e5306","tarball":"https://registry.npmjs.org/@kikobeats/cacheable-request/-/cacheable-request-7.0.5.tgz","fileCount":4,"integrity":"sha512-p2sUItZrbSS3OXS83pyks4vlT1msJJA5hFiMKREp5+cuGEzMAjTpOa/DOvOtshzG3XE/YNrs3O9ETqXCDPZWyA==","signatures":[{"sig":"MEUCID+u2AcAP14SRzuzX7zsObFDxF5VwFbKCbfXF4y/svGRAiEAqJUHggnkKiSTEcv79wwlT0hEEqTHo0PNcqi0WkdnU8k=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":18854},"jest":{"testMatch":["**/test/**/*.js"],"testEnvironment":"node","moduleFileExtensions":["js"]},"main":"src/index.js","_from":"file:kikobeats-cacheable-request-7.0.5.tgz","engines":{"node":">=18"},"scripts":{"test":"c8 jest","postinstall":"[ -f src/clone-response.js ] || echo \"export { default as cloneResponse } from 'clone-response'\" | esbuild --bundle --target=ES2019 --format=cjs --platform=node > src/clone-response.js"},"_npmUser":{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"},"_resolved":"/private/var/folders/wl/c4tw_5s97c9b26n2cj99x4180000gn/T/65b58f22a933ef2a72cd59ecf3701e34/kikobeats-cacheable-request-7.0.5.tgz","_integrity":"sha512-p2sUItZrbSS3OXS83pyks4vlT1msJJA5hFiMKREp5+cuGEzMAjTpOa/DOvOtshzG3XE/YNrs3O9ETqXCDPZWyA==","repository":{"url":"git+https://github.com/@kikobeats/cacheable-request.git","type":"git"},"_npmVersion":"10.5.2","description":"Wrap native HTTP requests with RFC compliant cache support","directories":{},"_nodeVersion":"20.13.0","dependencies":{"keyv":"^4.5.4","esbuild":"~0.21.1","responselike":"^2.0.0","normalize-url":"^6.0.3","clone-response":"^2.0.0","http-cache-semantics":"^4.1.1"},"_hasShrinkwrap":false,"devDependencies":{"c8":"latest","jest":"latest","sqlite3":"latest","standard":"latest","get-stream":"5","@keyv/sqlite":"latest","create-test-server":"latest"},"_npmOperationalInternal":{"tmp":"tmp/cacheable-request_7.0.5_1715428402759_0.8016396505118089","host":"s3://npm-registry-packages"}},"7.0.6":{"name":"@kikobeats/cacheable-request","version":"7.0.6","keywords":["7234","HTTP","HTTPS","RFC","RFC 7234","cache","cacheable","caching","compliant","layer"],"author":{"url":"https://kikobeats.com","name":"Kiko Beats","email":"josefrancisco.verdu@gmail.com"},"license":"MIT","_id":"@kikobeats/cacheable-request@7.0.6","maintainers":[{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"}],"homepage":"https://github.com/@kikobeats/cacheable-request#readme","bugs":{"url":"https://github.com/@kikobeats/cacheable-request/issues"},"dist":{"shasum":"12e442b3eb3e8bae72030d98417046561cf28667","tarball":"https://registry.npmjs.org/@kikobeats/cacheable-request/-/cacheable-request-7.0.6.tgz","fileCount":4,"integrity":"sha512-gNj1BP+Z/8+y8fyYo9+Up9pSJyMabAG7Bd+tcrph//wPRX404ovkI9bxldAPPxIKSodD3DLP79aI6/vN1IHnng==","signatures":[{"sig":"MEUCIQDYX+aqVHFnahG/IWQq7mGPUHqNqp/IZIp/t4ZL8Wxq0wIgTtKuETxc8al+7PF0JEQH+Ai1WpDgaJvOgrUW52KWraM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":18833},"jest":{"testMatch":["**/test/**/*.js"],"testEnvironment":"node","moduleFileExtensions":["js"]},"main":"src/index.js","engines":{"node":">=18"},"scripts":{"test":"c8 jest","postinstall":"[ -f src/clone-response.js ] || echo \"export { default as cloneResponse } from 'clone-response'\" | esbuild --bundle --target=ES2019 --format=cjs --platform=node > src/clone-response.js"},"_npmUser":{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"},"repository":{"url":"git+https://github.com/@kikobeats/cacheable-request.git","type":"git"},"description":"Wrap native HTTP requests with RFC compliant cache support","directories":{},"_nodeVersion":"24.16.0","dependencies":{"keyv":"^4.5.4","esbuild":"~0.21.1","responselike":"^2.0.0","normalize-url":"^6.0.3","clone-response":"^2.0.0","http-cache-semantics":"^4.1.1"},"_hasShrinkwrap":false,"devDependencies":{"c8":"latest","jest":"latest","standard":"latest","get-stream":"5","create-test-server":"latest"},"_npmOperationalInternal":{"tmp":"tmp/cacheable-request_7.0.6_1782979205443_0.42391481203396375","host":"s3://npm-registry-packages-npm-production"}},"7.0.7":{"_id":"@kikobeats/cacheable-request@7.0.7","bugs":{"url":"https://github.com/@kikobeats/cacheable-request/issues"},"dist":{"shasum":"1c2166f0b446a2f6f412b3f3c6e4e308e6408a80","tarball":"https://registry.npmjs.org/@kikobeats/cacheable-request/-/cacheable-request-7.0.7.tgz","fileCount":5,"integrity":"sha512-bEA02SGb+nb6DZUWBA5gTifY5S8f6ZiJcFw0LIs1D+jeYtC9EEbF9DUsqFcsQjv6ZL76WPXciLofOcIzdFFtJA==","signatures":[{"sig":"MEQCIEwrkwXQwIlxK8RC+qEF1cOmHPOyc9YhGU2MCsVxcOfYAiA1JdTyo2SihcZC5eNSm/xbBf5/HPT7QdVF0HqG4mo9KA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCSoetqfoXeDLDKvFoEdEzrjIXw0tk2+uklTbXPvD0nmgIgZceMEHQK5SLPzc4T33mU+Ee5RtB/zJwBLYZ149NLsxc="}],"unpackedSize":21948},"jest":{"testMatch":["**/test/**/*.js"],"testEnvironment":"node","moduleFileExtensions":["js"]},"main":"src/index.js","name":"@kikobeats/cacheable-request","author":{"url":"https://kikobeats.com","name":"Kiko Beats","email":"josefrancisco.verdu@gmail.com"},"engines":{"node":">=18"},"license":"MIT","scripts":{"test":"c8 jest","build":"echo \"export { default as cloneResponse } from 'clone-response'\" | esbuild --bundle --target=ES2019 --format=cjs --platform=node > src/clone-response.js","pretest":"npm run build"},"version":"7.0.7","_npmUser":{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"},"homepage":"https://github.com/@kikobeats/cacheable-request#readme","keywords":["7234","HTTP","HTTPS","RFC","RFC 7234","cache","cacheable","caching","compliant","layer"],"repository":{"url":"git+https://github.com/@kikobeats/cacheable-request.git","type":"git"},"description":"Wrap native HTTP requests with RFC compliant cache support","directories":{},"maintainers":[{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"}],"_nodeVersion":"24.16.0","dependencies":{"keyv":"^4.5.4","responselike":"^2.0.0","normalize-url":"^6.0.3","clone-response":"^2.0.0","http-cache-semantics":"^4.1.1"},"_hasShrinkwrap":false,"devDependencies":{"c8":"latest","jest":"latest","esbuild":"latest","standard":"latest","get-stream":"5","create-test-server":"latest"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/cacheable-request_7.0.7_1789632907833_0.6382387513861623"}}},"time":{"created":"2023-04-17T20:05:41.064Z","modified":"2026-09-17T08:15:08.141Z","7.0.3":"2023-04-17T20:05:41.275Z","7.0.4":"2024-05-11T11:18:27.379Z","7.0.5":"2024-05-11T11:53:22.922Z","7.0.6":"2026-07-02T08:00:05.629Z","7.0.7":"2026-09-17T08:15:07.916Z"},"bugs":{"url":"https://github.com/@kikobeats/cacheable-request/issues"},"author":{"url":"https://kikobeats.com","name":"Kiko Beats","email":"josefrancisco.verdu@gmail.com"},"license":"MIT","homepage":"https://github.com/@kikobeats/cacheable-request#readme","keywords":["7234","HTTP","HTTPS","RFC","RFC 7234","cache","cacheable","caching","compliant","layer"],"repository":{"url":"git+https://github.com/@kikobeats/cacheable-request.git","type":"git"},"description":"Wrap native HTTP requests with RFC compliant cache support","maintainers":[{"name":"kikobeats","email":"josefrancisco.verdu@gmail.com"}],"readme":"# cacheable-request\n\n> Wrap native HTTP requests with RFC compliant cache support\n\n[![Build Status](https://travis-ci.org/lukechilds/cacheable-request.svg?branch=master)](https://travis-ci.org/lukechilds/cacheable-request)\n[![Coverage Status](https://coveralls.io/repos/github/lukechilds/cacheable-request/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/cacheable-request?branch=master)\n[![npm](https://img.shields.io/npm/dm/cacheable-request.svg)](https://www.npmjs.com/package/cacheable-request)\n[![npm](https://img.shields.io/npm/v/cacheable-request.svg)](https://www.npmjs.com/package/cacheable-request)\n\n[RFC 7234](http://httpwg.org/specs/rfc7234.html) compliant HTTP caching for native Node.js HTTP/HTTPS requests. Caching works out of the box in memory or is easily pluggable with a wide range of storage adapters.\n\n**Note:** This is a low level wrapper around the core HTTP modules, it's not a high level request library.\n\n## Features\n\n- Only stores cacheable responses as defined by RFC 7234\n- Fresh cache entries are served directly from cache\n- Stale cache entries are revalidated with `If-None-Match`/`If-Modified-Since` headers\n- 304 responses from revalidation requests use cached body\n- Updates `Age` header on cached responses\n- Can completely bypass cache on a per request basis\n- In memory cache by default\n- Official support for Redis, MongoDB, SQLite, PostgreSQL and MySQL storage adapters\n- Easily plug in your own or third-party storage adapters\n- If DB connection fails, cache is automatically bypassed ([disabled by default](#optsautomaticfailover))\n- Adds cache support to any existing HTTP code with minimal changes\n- Uses [http-cache-semantics](https://github.com/pornel/http-cache-semantics) internally for HTTP RFC 7234 compliance\n\n## Install\n\n```shell\nnpm install cacheable-request\n```\n\n## Usage\n\n```js\nconst http = require('http');\nconst CacheableRequest = require('cacheable-request');\n\n// Then instead of\nconst req = http.request('http://example.com', cb);\nreq.end();\n\n// You can do\nconst cacheableRequest = new CacheableRequest(http.request);\nconst cacheReq = cacheableRequest('http://example.com', cb);\ncacheReq.on('request', req => req.end());\n// Future requests to 'example.com' will be returned from cache if still valid\n\n// You pass in any other http.request API compatible method to be wrapped with cache support:\nconst cacheableRequest = new CacheableRequest(https.request);\nconst cacheableRequest = new CacheableRequest(electron.net);\n```\n\n## Storage Adapters\n\n`cacheable-request` uses [Keyv](https://github.com/lukechilds/keyv) to support a wide range of storage adapters.\n\nFor example, to use Redis as a cache backend, you just need to install the official Redis Keyv storage adapter:\n\n```\nnpm install @keyv/redis\n```\n\nAnd then you can pass `CacheableRequest` your connection string:\n\n```js\nconst cacheableRequest = new CacheableRequest(http.request, 'redis://user:pass@localhost:6379');\n```\n\n[View all official Keyv storage adapters.](https://github.com/lukechilds/keyv#official-storage-adapters)\n\nKeyv also supports anything that follows the Map API so it's easy to write your own storage adapter or use a third-party solution.\n\ne.g The following are all valid storage adapters\n\n```js\nconst storageAdapter = new Map();\n// or\nconst storageAdapter = require('./my-storage-adapter');\n// or\nconst QuickLRU = require('quick-lru');\nconst storageAdapter = new QuickLRU({ maxSize: 1000 });\n\nconst cacheableRequest = new CacheableRequest(http.request, storageAdapter);\n```\n\nView the [Keyv docs](https://github.com/lukechilds/keyv) for more information on how to use storage adapters.\n\n## API\n\n### new cacheableRequest(request, [storageAdapter])\n\nReturns the provided request function wrapped with cache support.\n\n#### request\n\nType: `function`\n\nRequest function to wrap with cache support. Should be [`http.request`](https://nodejs.org/api/http.html#http_http_request_options_callback) or a similar API compatible request function.\n\n#### storageAdapter\n\nType: `Keyv storage adapter`<br>\nDefault: `new Map()`\n\nA [Keyv](https://github.com/lukechilds/keyv) storage adapter instance, or connection string if using with an official Keyv storage adapter.\n\n### Instance\n\n#### cacheableRequest(opts, [cb])\n\nReturns an event emitter.\n\n##### opts\n\nType: `object`, `string`\n\n- Any of the default request functions options.\n- Any [`http-cache-semantics`](https://github.com/kornelski/http-cache-semantics#constructor-options) options.\n- Any of the following:\n\n###### opts.cache\n\nType: `boolean`<br>\nDefault: `true`\n\nIf the cache should be used. Setting this to false will completely bypass the cache for the current request.\n\n###### opts.strictTtl\n\nType: `boolean`<br>\nDefault: `false`\n\nIf set to `true` once a cached resource has expired it is deleted and will have to be re-requested.\n\nIf set to `false` (default), after a cached resource's TTL expires it is kept in the cache and will be revalidated on the next request with `If-None-Match`/`If-Modified-Since` headers.\n\n###### opts.maxTtl\n\nType: `number`<br>\nDefault: `undefined`\n\nLimits TTL. The `number` represents milliseconds.\n\n###### opts.automaticFailover\n\nType: `boolean`<br>\nDefault: `false`\n\nWhen set to `true`, if the DB connection fails we will automatically fallback to a network request. DB errors will still be emitted to notify you of the problem even though the request callback may succeed.\n\n###### opts.forceRefresh\n\nType: `boolean`<br>\nDefault: `false`\n\nForces refreshing the cache. If the response could be retrieved from the cache, it will perform a new request and override the cache instead.\n\n##### cb\n\nType: `function`\n\nThe callback function which will receive the response as an argument.\n\nThe response can be either a [Node.js HTTP response stream](https://nodejs.org/api/http.html#http_class_http_incomingmessage) or a [responselike object](https://github.com/lukechilds/responselike). The response will also have a `fromCache` property set with a boolean value.\n\n##### .on('request', request)\n\n`request` event to get the request object of the request.\n\n**Note:** This event will only fire if an HTTP request is actually made, not when a response is retrieved from cache. However, you should always handle the `request` event to end the request and handle any potential request errors.\n\n##### .on('response', response)\n\n`response` event to get the response object from the HTTP request or cache.\n\n##### .on('error', error)\n\n`error` event emitted in case of an error with the cache.\n\nErrors emitted here will be an instance of `CacheableRequest.RequestError` or `CacheableRequest.CacheError`. You will only ever receive a `RequestError` if the request function throws (normally caused by invalid user input). Normal request errors should be handled inside the `request` event.\n\nTo properly handle all error scenarios you should use the following pattern:\n\n```js\ncacheableRequest('example.com', cb)\n  .on('error', err => {\n    if (err instanceof CacheableRequest.CacheError) {\n      handleCacheError(err); // Cache error\n    } else if (err instanceof CacheableRequest.RequestError) {\n      handleRequestError(err); // Request function thrown\n    }\n  })\n  .on('request', req => {\n    req.on('error', handleRequestError); // Request error emitted\n    req.end();\n  });\n```\n\n**Note:** Database connection errors are emitted here, however `cacheable-request` will attempt to re-request the resource and bypass the cache on a connection error. Therefore a database connection error doesn't necessarily mean the request won't be fulfilled.\n\n## License\n\nMIT © Luke Childs\n","readmeFilename":""}