Skip to content

Commit

Permalink
correct cache source
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiancook committed Dec 3, 2023
1 parent cdd4ff1 commit 347b701
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/worker/service-worker/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,8 @@ export async function createRouter(serviceWorkers?: DurableServiceWorkerRegistra
}
if (isRouterSourceType(ruleSource, "cache")) {
if (isRouterCacheSource(ruleSource)) {
if (ruleSource.request) {
// TODO, should this match the actual request properties
// or should it only match the exact reference of this request
if (ruleSource.request !== input) {
return undefined;
}
}
const cache = await caches.open(ruleSource.cacheName || "default");
return cache.match(cacheKey());
return cache.match(cacheKey(ruleSource.request));
} else {
const cache = await caches.open("default");
return cache.match(cacheKey())
Expand All @@ -488,7 +481,14 @@ export async function createRouter(serviceWorkers?: DurableServiceWorkerRegistra
throw new Error("Unknown source type");
}

function cacheKey() {
function cacheKey(request?: RequestInfo) {
if (request) {
if (request instanceof Request) {
return request.clone();
} else {
return new Request(request);
}
}
if (!init) {
return clone();
} else {
Expand Down

0 comments on commit 347b701

Please sign in to comment.