GitHunt

fastify-disablecache

GitHub Release
npm version
CI
Coverage status
code style: Prettier

Fastify plugin to disable client-side caching

Overview

Inspired by nocache, the fastify-disablecache plugin sets the following response headers and values to disable client-side caching:

Cache-Control: no-store, max-age=0, must-revalidate, proxy-revalidate
Expires: 0
Pragma: no-cache
Surrogate-Control: no-store

This plugin was created out of a need for an easy way to disable client-side caching for data received from backend APIs. This ensures data is always current when called by applications.

Why these headers?

  • Cache-Control - Primary response header for configuring cache controls since HTTP/1.1; whilst no-store is the directive to disable caching, clients such as Internet Explorer did not use it, thus the addition of max-age=0, must-revalidate; proxy-revalidate is added to ensure legacy proxies that only partially implemented support for must-revalidate also revalidate the response
  • Expires - Included for backwards compatibility with HTTP/1.0 caches
  • Pragma - Included for backwards compatibility with HTTP/1.0 caches, is used by Internet Explorer
  • Surrogate-Control - Not a standardised response header but is used by CDNs and reverse proxies for cache control

Installation

Install using npm:

npm i fastify-disablecache

Compatibility

Plugin version Fastify version
>=4.x ^5.x
>=3.x <4.x ^4.x
>=1.x <3.x ^3.x

Please note that if a Fastify version is out of support, then so are the corresponding versions of this plugin
in the table above.
See Fastify's LTS policy for more details.

Example usage

const Fastify = require("fastify");
const disableCache = require("fastify-disablecache");

const server = Fastify();
server.register(disableCache);

server.get("/", (_req, res) => {
	res.send("ok");
});

server.listen(3000, (err) => {
	if (err) throw err;
	console.log("Server listening on 3000");
});

Contributing

Contributions are welcome, and any help is greatly appreciated!

See the contributing guide for details on how to get started.
Please adhere to this project's Code of Conduct when contributing.

Acknowledgements

License

fastify-disablecache is licensed under the MIT license.

Languages

JavaScript100.0%

Contributors

MIT License
Created January 11, 2021
Updated March 6, 2026