fastify-response-caching

0.0.4 • Public • Published

fastify-response-caching

Node.js CI

fastify-response-caching is a plugin for the Fastify 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.

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.

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.

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:

{
  ttl: <Number>
  additionalCondition: {
    headers: <Array<String>>
  }
}
  • 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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.4
    17
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.4
    17
  • 0.0.3
    16
  • 0.0.2
    0
  • 0.0.1
    0

Package Sidebar

Install

npm i fastify-response-caching

Weekly Downloads

33

Version

0.0.4

License

MIT

Unpacked Size

7.67 kB

Total Files

4

Last publish

Collaborators

  • codeaholicguy