Last active
January 23, 2024 09:17
-
-
Save pitzcarraldo/22c27ac20b6ab5df1f77c31ae20f68aa to your computer and use it in GitHub Desktop.
example to use cf cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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