feat(cache): add Cache-Control middleware and update .env.example

This commit is contained in:
Abdelaziz Mahdy
2024-12-22 15:32:56 -04:00
parent 2d5377cbc5
commit f1f5db84f9
3 changed files with 23 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
import type { MiddlewareHandler } from "hono";
// Define middleware to add Cache-Control header
const cacheControlMiddleware: MiddlewareHandler = async (c, next) => {
const sMaxAge = process.env.S_MAXAGE || "60";
const staleWhileRevalidate = process.env.STALE_WHILE_REVALIDATE || "30";
c.header(
"Cache-Control",
`s-maxage=${sMaxAge}, stale-while-revalidate=${staleWhileRevalidate}`
);
await next();
};
export default cacheControlMiddleware;