fastify-disablecache
Advanced tools
+2
-2
| { | ||
| "name": "fastify-disablecache", | ||
| "version": "4.0.2", | ||
| "version": "5.0.0", | ||
| "description": "Fastify plugin to disable client-side caching", | ||
@@ -35,4 +35,4 @@ "keywords": [ | ||
| "dependencies": { | ||
| "fastify-plugin": "^5.0.1" | ||
| "fastify-plugin": "^5.1.0" | ||
| } | ||
| } |
+11
-1
@@ -39,4 +39,14 @@ # fastify-disablecache | ||
| For Fastify v4.x support, use `fastify-disablecache@3.1.9`. | ||
| ### 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](https://github.com/fastify/fastify/blob/main/docs/Reference/LTS.md) for more details. | ||
| ## Example usage | ||
@@ -43,0 +53,0 @@ |
+18
-9
@@ -6,6 +6,6 @@ "use strict"; | ||
| const CACHE_HEADERS = { | ||
| "Cache-Control": "no-store, max-age=0, must-revalidate", | ||
| Expires: "0", | ||
| Pragma: "no-cache", | ||
| "Surrogate-Control": "no-store", | ||
| "cache-control": "no-store, max-age=0, must-revalidate", | ||
| expires: "0", | ||
| pragma: "no-cache", | ||
| "surrogate-control": "no-store", | ||
| }; | ||
@@ -15,10 +15,19 @@ | ||
| * @author Frazer Smith | ||
| * @description Adds cache disabling headers to the response. | ||
| * @type {import("fastify").onRequestHookHandler} | ||
| */ | ||
| function setCacheHeaders(_req, res, done) { | ||
| res.headers(CACHE_HEADERS); | ||
| done(); | ||
| } | ||
| /** | ||
| * @author Frazer Smith | ||
| * @description Simple plugin that adds an `onRequest` hook to disable client-side caching | ||
| * by setting the relevant response headers. | ||
| * @param {import("fastify").FastifyInstance} server - Fastify instance. | ||
| * @type {import("fastify").FastifyPluginCallback} | ||
| */ | ||
| async function fastifyDisablecache(server) { | ||
| server.addHook("onRequest", async function setCacheHeaders(_req, res) { | ||
| res.headers(CACHE_HEADERS); | ||
| }); | ||
| function fastifyDisablecache(server, _options, done) { | ||
| server.addHook("onRequest", setCacheHeaders); | ||
| done(); | ||
| } | ||
@@ -25,0 +34,0 @@ |
+4
-4
@@ -1,5 +0,5 @@ | ||
| import type { FastifyPluginAsync } from "fastify"; | ||
| import type { FastifyPluginCallback } from "fastify"; | ||
| declare namespace fastifyDisablecache { | ||
| export const fastifyDisablecache: FastifyPluginAsync; | ||
| export const fastifyDisablecache: FastifyPluginCallback; | ||
| export { fastifyDisablecache as default }; | ||
@@ -9,4 +9,4 @@ } | ||
| declare function fastifyDisablecache( | ||
| ...params: Parameters<FastifyPluginAsync> | ||
| ): ReturnType<FastifyPluginAsync>; | ||
| ...params: Parameters<FastifyPluginCallback> | ||
| ): ReturnType<FastifyPluginCallback>; | ||
| export = fastifyDisablecache; |
7207
8.52%42
23.53%86
13.16%Updated