@zkochan/pnpm
Version:
Fast, disk space efficient package manager
123 lines (122 loc) • 10.5 kB
JSON
{
"_args": [
[
{
"raw": "cacheable-request@^2.1.1",
"scope": null,
"escapedName": "cacheable-request",
"name": "cacheable-request",
"rawSpec": "^2.1.1",
"spec": ">=2.1.1 <3.0.0",
"type": "range"
},
"/home/zkochan/src/pnpm/packages/pnpm/node_modules/got"
]
],
"_from": "cacheable-request@>=2.1.1 <3.0.0",
"_id": "cacheable-request@2.1.4",
"_inCache": true,
"_location": "/cacheable-request",
"_nodeVersion": "5.12.0",
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/cacheable-request-2.1.4.tgz_1514318995331_0.5610265193972737"
},
"_npmUser": {
"name": "lukechilds",
"email": "lukechilds123@gmail.com"
},
"_npmVersion": "3.8.6",
"_phantomChildren": {},
"_requested": {
"raw": "cacheable-request@^2.1.1",
"scope": null,
"escapedName": "cacheable-request",
"name": "cacheable-request",
"rawSpec": "^2.1.1",
"spec": ">=2.1.1 <3.0.0",
"type": "range"
},
"_requiredBy": [
"/got"
],
"_resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-2.1.4.tgz",
"_shasum": "0d808801b6342ad33c91df9d0b44dc09b91e5c3d",
"_shrinkwrap": null,
"_spec": "cacheable-request@^2.1.1",
"_where": "/home/zkochan/src/pnpm/packages/pnpm/node_modules/got",
"author": {
"name": "Luke Childs",
"email": "lukechilds123@gmail.com",
"url": "http://lukechilds.co.uk"
},
"bugs": {
"url": "https://github.com/lukechilds/cacheable-request/issues"
},
"dependencies": {
"clone-response": "1.0.2",
"get-stream": "3.0.0",
"http-cache-semantics": "3.8.1",
"keyv": "3.0.0",
"lowercase-keys": "1.0.0",
"normalize-url": "2.0.1",
"responselike": "1.0.2"
},
"description": "Wrap native HTTP requests with RFC compliant cache support",
"devDependencies": {
"@keyv/sqlite": "^1.2.6",
"ava": "^0.24.0",
"coveralls": "^3.0.0",
"create-test-server": "^2.0.0",
"delay": "^2.0.0",
"eslint-config-xo-lukechilds": "^1.0.0",
"nyc": "^11.0.2",
"pify": "^3.0.0",
"sqlite3": "^3.1.9",
"this": "^1.0.2",
"xo": "^0.19.0"
},
"directories": {},
"dist": {
"shasum": "0d808801b6342ad33c91df9d0b44dc09b91e5c3d",
"tarball": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-2.1.4.tgz"
},
"gitHead": "3f2d8e2f64af835a82721c51898bd6f08883c4de",
"homepage": "https://github.com/lukechilds/cacheable-request",
"keywords": [
"HTTP",
"HTTPS",
"cache",
"caching",
"layer",
"cacheable",
"RFC 7234",
"RFC",
"7234",
"compliant"
],
"license": "MIT",
"main": "src/index.js",
"maintainers": [
{
"name": "lukechilds",
"email": "lukechilds123@gmail.com"
}
],
"name": "cacheable-request",
"optionalDependencies": {},
"readme": "# cacheable-request\n\n> Wrap native HTTP requests with RFC compliant cache support\n\n[](https://travis-ci.org/lukechilds/cacheable-request)\n[](https://coveralls.io/github/lukechilds/cacheable-request?branch=master)\n[](https://www.npmjs.com/package/cacheable-request)\n[](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 --save 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 --save @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\nAny of the default request functions options plus:\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 `false`, 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\nIf set to `true` once a cached resource has expired it is deleted and will have to be re-requested.\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##### 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": "README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/lukechilds/cacheable-request.git"
},
"scripts": {
"coverage": "nyc report --reporter=text-lcov | coveralls",
"test": "xo && nyc ava"
},
"version": "2.1.4",
"xo": {
"extends": "xo-lukechilds"
}
}