You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
I am having issues around caching dynamic content on beta16. I found with the "freshness" strategy none of my api requests were hitting the cache. This was due to the fetch method making a request and resolving the promise with the actual response from the server which was 503. Because of this the fetchFromCache code block is never executed and you are left with 503s. See explanation below.
freshness.ts
The call to fetchAndCache fails but returns a response object with a 503 status code.
constunrestrictedFetch=group// Make a request to the network and cache the result, irrespective of the// timeout..fetchAndCache(req,delegate)// If this operation fails (note that a failed HTTP status code is still// counted as success, treat it as an unavailable response.// TODO: allow more control over what constitutes request failure and// what happens in the case of failure..catch(()=>({response: null}asResponseWithSideEffect));// By default, wait for the network request indefinitely.letnetworkFetch=unrestrictedFetch;
When networkFetch resolves the first if block checks if response is null and if it is executes. In this case we have a valid response object so the cache isn't hit.
returnnetworkFetch.then(rse=>{if(rse.response===null){// Network request failed or timed out. Check the cache to see if// this request is available there.returngroup.fetchFromCache(req).then(cacheRse=>{// Regardless of whether the cache hit, the network request may// still be going, so set up a side effect that runs the cache// effect first and the network effect following. This ensures// the network result will be cached if/when it comes back.constsideEffect=()=>maybeRun(cacheRse.sideEffect).then(()=>unrestrictedFetch).then(netRse=>maybeRun(netRse.sideEffect));
I changed the condition as below and it works for me now.
if(rse.response===null||!rse.response.ok){
The text was updated successfully, but these errors were encountered:
I am having issues around caching dynamic content on beta16. I found with the "freshness" strategy none of my api requests were hitting the cache. This was due to the fetch method making a request and resolving the promise with the actual response from the server which was 503. Because of this the fetchFromCache code block is never executed and you are left with 503s. See explanation below.
freshness.ts
The call to fetchAndCache fails but returns a response object with a 503 status code.
When networkFetch resolves the first if block checks if response is null and if it is executes. In this case we have a valid response object so the cache isn't hit.
I changed the condition as below and it works for me now.
The text was updated successfully, but these errors were encountered: