From cbe0e14809ae8bf71ca06e5fb3b564d93d5a042b Mon Sep 17 00:00:00 2001 From: Edmund Hung Date: Sun, 11 Feb 2024 15:03:06 +0100 Subject: [PATCH] feat: setup kv cache --- app/services/github.server.ts | 4 ++-- env.d.ts | 2 +- wrangler.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/services/github.server.ts b/app/services/github.server.ts index 51d87b5..bd23569 100644 --- a/app/services/github.server.ts +++ b/app/services/github.server.ts @@ -56,7 +56,7 @@ export async function getFileContentWithCache( path: string, ): Promise { const key = `github/${path}`; - const cache = await context.env.CACHE.get(key); + const cache = await context.env.cache.get(key); if (cache) { return cache; @@ -71,7 +71,7 @@ export async function getFileContentWithCache( // Update the cache // TODO: Use `waitUntil` to update the cache in the background - await context.env.CACHE.put(key, content, { expirationTtl: 60 * 60 }); + await context.env.cache.put(key, content, { expirationTtl: 60 * 60 }); return content; } diff --git a/env.d.ts b/env.d.ts index 973e98e..cc30c92 100644 --- a/env.d.ts +++ b/env.d.ts @@ -5,7 +5,7 @@ import '@cloudflare/workers-types'; interface Env { ENVIRONMENT?: 'development'; GITHUB_TOKEN?: string; - CACHE: KVNamespace; + cache: KVNamespace; } declare module '@remix-run/cloudflare' { diff --git a/wrangler.toml b/wrangler.toml index d829a1f..2ebd589 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -1,4 +1,4 @@ name = "remix-cloudflare-template" kv_namespaces = [ - { id = "CACHE", binding="CACHE" } + { binding = "cache", id = "7bd353e1660544f497319275f6e241fa" } ] \ No newline at end of file