Skip to content

Commit

Permalink
Remove url transform in platform cache
Browse files Browse the repository at this point in the history
  • Loading branch information
danopia committed Sep 23, 2024
1 parent cede987 commit 734f543
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions generation/deploy/cache-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ import { trace } from "./tracer.ts";

// https://docs.deno.com/deploy/manual/edge-cache

function transformUrl(url: string) {
return url.replace(/\/\/[^\/]+\//, '//upstream-cache-v2/');
}

export async function platformCache(
name = 'http-policy-cache',
name = 'http-policy-cache-v2',
): Promise<Cache> {

const nativeCache = await caches.open(name);

return new Cache({

async get(url) {
const cached = await nativeCache.match(transformUrl(url));
const cached = await nativeCache.match(url);
if (!cached) return undefined;

type CachePolicy = Parameters<ConstructorParameters<typeof Cache>[0]['set']>[1]['policy'];
Expand Down Expand Up @@ -48,7 +44,7 @@ export async function platformCache(

async set(url, resp) {
const {resh, ...rest} = resp.policy;
await nativeCache.put(transformUrl(url), new Response(resp.body, {
await nativeCache.put(url, new Response(resp.body, {
headers: {
...resh,
'x-cache-policy': JSON.stringify(rest),
Expand All @@ -57,7 +53,7 @@ export async function platformCache(
},

async delete(url) {
await nativeCache.delete(transformUrl(url));
await nativeCache.delete(url);
},

close() {},
Expand Down

0 comments on commit 734f543

Please sign in to comment.