use-http icon indicating copy to clipboard operation
use-http copied to clipboard

[Bug] useFetch with no cache policy caches on 500+

Open jakelheknight opened this issue 5 years ago • 2 comments

    const { loading, get } = useFetch(
        `${apiGateWayEndpoint}/api/v1/schdule`,
        {
            headers: {
                'Content-Type': 'application/json',
            },
            redirect: 'follow',
            cachePolicy: CachePolicies.NO_CACHE,
        }
    );

   getData = async (id) => {
     get(`?id=${id}`);
  }

Is caching somehow and returning the previous ID's data on a 500+ error.

jakelheknight avatar Sep 29 '20 04:09 jakelheknight

Could you make a codesandbox reproducing the bug please?

iamthesiz avatar Sep 29 '20 18:09 iamthesiz

I think it's hard to prepare codesandbox for this but I do confirm that issue. The thing is you would have to prepare an API that will give the response on first time but will fail with the same request next time.

So if cachePolicy is set to default and you make a success response, and next time you change policy to no-cache AND make response failed, even then data is returning value from the previous cached request.

I think a workaround for @jakelheknight would be to add some query params to URL. But still, this is a bug in my opinion because no-cache should not return data from the previous responses. Now it returns even of new request is not made or failed

igor-krupa avatar Aug 18 '21 13:08 igor-krupa