Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/codeaholicguy/fastify-response-caching
A Fastify plugin for caching the response
https://github.com/codeaholicguy/fastify-response-caching
fastify fastify-response-caching response-caching
Last synced: 3 months ago
JSON representation
A Fastify plugin for caching the response
- Host: GitHub
- URL: https://github.com/codeaholicguy/fastify-response-caching
- Owner: codeaholicguy
- License: mit
- Created: 2020-09-17T03:33:36.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-12-05T11:24:22.000Z (about 2 years ago)
- Last Synced: 2024-10-15T01:42:35.923Z (3 months ago)
- Topics: fastify, fastify-response-caching, response-caching
- Language: JavaScript
- Homepage:
- Size: 140 KB
- Stars: 17
- Watchers: 2
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-response-caching
![Node.js CI](https://github.com/codeaholicguy/fastify-response-caching/workflows/Node.js%20CI/badge.svg)
*fastify-response-caching* is a plugin for the [Fastify](http://fastify.io/) framework
that provides mechanisms for caching response to reduce the server workload.By default, this plugin implements caching by request URL (includes all query parameters)
with the caching time (TTL) is 1 seconds. Besides, this plugin also supports additional caching condition
such as request headers.## Example
This example shows using the plugin to cache response with default options.
```js
const fastify = require('fastify')
const fastifyResponseCaching = require('fastify-response-caching')fastify.register(fastifyResponseCaching)
```This example shows using the plugin to cache response with customized caching time.
```js
const fastify = require('fastify')
const fastifyResponseCaching = require('fastify-response-caching')fastify.register(fastifyResponseCaching, {ttl: 5000})
```This example shows using the plugin to cache response with customized caching conditions.
```js
const fastify = require('fastify')
const fastifyResponseCaching = require('fastify-response-caching')fastify.register(fastifyResponseCaching, {ttl: 5000, headers: ['x-request-agent']})
```## API
### Options
*fastify-response-caching* accepts the options object:
```js
{
ttl:
additionalCondition: {
headers: >
}
}
```+ `ttl` (Default: `1000`): a value, in milliseconds, for the lifetime of the response cache.
+ `additionalCondition` (Default: `undefined`): a configuration of additional condition for caching.
+ `additionalCondition.headers` (Default: `[]`): a list of string, headers that you want to include in the caching condition.## License
[MIT License](LICENSE)