Skip to content

Instantly share code, notes, and snippets.

@pitzcarraldo
Last active January 23, 2024 09:17
Show Gist options
  • Save pitzcarraldo/22c27ac20b6ab5df1f77c31ae20f68aa to your computer and use it in GitHub Desktop.
Save pitzcarraldo/22c27ac20b6ab5df1f77c31ae20f68aa to your computer and use it in GitHub Desktop.
example to use cf cache
async function handleRequest(
c: any,
args: any
): Promise<any> {
const cacheKey = new URL(c.req.url).toString();
const cachedResponse = await caches.default.match(cacheKey);
if (cachedResponse) {
return c.json(await cachedResponse.json());
}
// Business Logic
const data = ...
const response = await cacheResponse(
cacheKey,
data,
);
return c.json(await response.json());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment