Skip to content

Commit

Permalink
feat: setup kv cache
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundhung committed Feb 11, 2024
1 parent 194c8eb commit cbe0e14
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/services/github.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function getFileContentWithCache(
path: string,
): Promise<string> {
const key = `github/${path}`;
const cache = await context.env.CACHE.get(key);
const cache = await context.env.cache.get(key);

if (cache) {
return cache;
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import '@cloudflare/workers-types';
interface Env {
ENVIRONMENT?: 'development';
GITHUB_TOKEN?: string;
CACHE: KVNamespace<string>;
cache: KVNamespace<string>;
}

declare module '@remix-run/cloudflare' {
Expand Down
2 changes: 1 addition & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "remix-cloudflare-template"
kv_namespaces = [
{ id = "CACHE", binding="CACHE" }
{ binding = "cache", id = "7bd353e1660544f497319275f6e241fa" }
]

0 comments on commit cbe0e14

Please sign in to comment.