import { json } from "@remix-run/react";
export const loader: LoaderFunction = async ({ request, context, params }) => {
const url = new URL(request.url);
const cacheKey = new Request(url.toString(), request);
const cache = context.cloudflare.caches.default;
const cacheEntry = await cache.match(cacheKey);
let users = (await cacheEntry?.json())?.users;
if (!users) {
const query = url.searchParams.get("query");
const db = await context.db;
users = await db.query(query);
context.cloudflare.ctx.waitUntil(
cache.put(
cacheKey,
json(users, {
headers: {
Expires: new Date(
new Date().setFullYear(new Date().getFullYear() + 1),
).toUTCString(),
},
}),
),
);
}
...
}
import { json } from "@remix-run/react";
export const loader: LoaderFunction = async ({ request, context, params }) => {
const url = new URL(request.url);
const cacheKey = new Request(url.toString(), request);
const cache = context.cloudflare.caches.default;
const cacheEntry = await cache.match(cacheKey);
let users = (await cacheEntry?.json())?.users;
if (!users) {
const query = url.searchParams.get("query");
const db = await context.db;
users = await db.query(query);
context.cloudflare.ctx.waitUntil(
cache.put(
cacheKey,
json(users, {
headers: {
Expires: new Date(
new Date().setFullYear(new Date().getFullYear() + 1),
).toUTCString(),
},
}),
),
);
}
...
}