diff --git a/src/lib/async.ts b/src/lib/async.ts index 33788de94..5e0523777 100644 --- a/src/lib/async.ts +++ b/src/lib/async.ts @@ -85,7 +85,7 @@ export async function race( const done = () => { resolved = true; if (timeoutId) { - clearTimeout(timeoutId!); + clearTimeout(timeoutId); } if (blockTimeoutId) { clearTimeout(blockTimeoutId); diff --git a/src/lib/cache/cache.ts b/src/lib/cache/cache.ts index fd8a53eaa..c385a4f3d 100644 --- a/src/lib/cache/cache.ts +++ b/src/lib/cache/cache.ts @@ -177,12 +177,16 @@ export function cache( // If the resolution came from a fetch (fromBackend is undefined), we don't need to update caches as it was // done in the revalidate function above. if (fromBackend?.replication === 'global') { - await waitUntil( + // Write and await to the memory cache, so future requests are guaranteed to hit it. + await memoryCache.set(key, savedEntry); + + // Write to other local caches, but don't await (debugging hanging pages) + waitUntil( Promise.all( cacheBackends .filter( (backend) => - backend.name !== backendName && backend.replication === 'local', + backend.name !== backendName && backend.name !== memoryCache.name && backend.replication === 'local', ) .map((backend) => backend.set(key, savedEntry)), ),