Per-page caching control
This commit is contained in:
parent
ba6de7244a
commit
c311c0921d
|
@ -4,7 +4,7 @@
|
|||
declare namespace App {
|
||||
interface Locals {
|
||||
currentLocale: string;
|
||||
notFound: boolean;
|
||||
sdkCalls: Set<string>;
|
||||
pageCaching: boolean;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ export const pageCachingMiddleware = defineMiddleware(async ({ url, request, loc
|
|||
if (response.ok) {
|
||||
response.headers.set("Last-Modified", new Date().toUTCString());
|
||||
|
||||
if (!pathname.includes("/api/")) {
|
||||
if (locals.pageCaching) {
|
||||
pageCache.set(pathname, response, [...locals.sdkCalls]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,5 +4,6 @@ import { getCurrentLocale } from "src/middleware/utils";
|
|||
export const setAstroLocalsMiddleware = defineMiddleware(async ({ url, locals }, next) => {
|
||||
locals.currentLocale = getCurrentLocale(url.pathname) ?? "en";
|
||||
locals.sdkCalls = new Set();
|
||||
locals.pageCaching = true;
|
||||
return next();
|
||||
});
|
||||
|
|
|
@ -3,8 +3,6 @@ import AppLayout from "components/AppLayout/AppLayout.astro";
|
|||
import Button from "components/Button.astro";
|
||||
import { getI18n } from "src/i18n/i18n";
|
||||
|
||||
Astro.locals.notFound = true;
|
||||
|
||||
const { t, getLocalizedUrl } = await getI18n(Astro.locals.currentLocale);
|
||||
---
|
||||
|
||||
|
|
|
@ -3,9 +3,10 @@ import { Collections } from "src/shared/payload/constants";
|
|||
import type { AfterOperationWebHookMessage } from "src/shared/payload/webhooks";
|
||||
import { contextCache, dataCache } from "src/services.ts";
|
||||
|
||||
export const POST: APIRoute = async ({ request }) => {
|
||||
const auth = request.headers.get("Authorization");
|
||||
export const POST: APIRoute = async ({ request, locals }) => {
|
||||
locals.pageCaching = false;
|
||||
|
||||
const auth = request.headers.get("Authorization");
|
||||
if (auth !== `Bearer ${import.meta.env.WEB_HOOK_TOKEN}`) {
|
||||
return new Response(null, { status: 403, statusText: "Forbidden" });
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import type { APIRoute } from "astro";
|
||||
import { dataCache, pageCache } from "src/services";
|
||||
|
||||
export const GET: APIRoute = async () => {
|
||||
export const GET: APIRoute = async ({ locals }) => {
|
||||
locals.pageCaching = false;
|
||||
|
||||
await dataCache.init();
|
||||
await pageCache.init();
|
||||
return new Response(null, { status: 200, statusText: "Ok" });
|
||||
|
|
|
@ -13,6 +13,7 @@ import PageCredits from "./_components/PageCredits.astro";
|
|||
import type { EndpointPage } from "src/shared/payload/endpoint-types";
|
||||
|
||||
export const partial = true;
|
||||
Astro.locals.pageCaching = false;
|
||||
|
||||
interface Props {
|
||||
lang?: string;
|
||||
|
|
|
@ -10,6 +10,7 @@ import type { EndpointChronologyEvent } from "src/shared/payload/endpoint-types"
|
|||
import { payload } from "src/services";
|
||||
|
||||
export const partial = true;
|
||||
Astro.locals.pageCaching = false;
|
||||
|
||||
interface Props {
|
||||
lang?: string;
|
||||
|
|
|
@ -18,6 +18,8 @@ import ChronologyEventPreview from "components/Previews/ChronologyEventPreview.a
|
|||
import { Collections } from "src/shared/payload/constants";
|
||||
import { meilisearch } from "src/services";
|
||||
|
||||
Astro.locals.pageCaching = false;
|
||||
|
||||
type State = {
|
||||
q: string;
|
||||
page: number;
|
||||
|
|
Loading…
Reference in New Issue