export const onRequest: PagesFunction<Env> = async (context) => {
const cacheKey = "https://site/source/data/all";
let myCache = await caches.open("custom:cache");
const cachedValue = await myCache.match(cacheKey);
console.log("Returned cache", cachedValue);
const value = { test: 1 };
let testing = null;
if (cachedValue) {
testing = await cachedValue.json();
console.log("Reading cache", testing);
// @ts-ignore no type defined due to testing
value.test = 1 + testing.test;
}
const headers = new Headers();
headers.append("content-type", "application/json");
headers.append("Cache-Control", `s-maxage=${180}`);
const cachedResponse = new Response(JSON.stringify(value), {
status: 200,
statusText: "Success",
headers: headers,
});
await myCache.put(cacheKey, cachedResponse);
return new Response(JSON.stringify(value));
};
export const onRequest: PagesFunction<Env> = async (context) => {
const cacheKey = "https://site/source/data/all";
let myCache = await caches.open("custom:cache");
const cachedValue = await myCache.match(cacheKey);
console.log("Returned cache", cachedValue);
const value = { test: 1 };
let testing = null;
if (cachedValue) {
testing = await cachedValue.json();
console.log("Reading cache", testing);
// @ts-ignore no type defined due to testing
value.test = 1 + testing.test;
}
const headers = new Headers();
headers.append("content-type", "application/json");
headers.append("Cache-Control", `s-maxage=${180}`);
const cachedResponse = new Response(JSON.stringify(value), {
status: 200,
statusText: "Success",
headers: headers,
});
await myCache.put(cacheKey, cachedResponse);
return new Response(JSON.stringify(value));
};