3

I made a react app with a Django Rest Framework backend, using Mac OS X with Chrome. When I refresh the app a few times, the app stops making the API call and starts to use cached data, even though I have no-cache and max-age headers. Interestingly, if the developer tools window is open, it always makes the API call and doesn't use the cached data. Is there a way to force the app to always make the API call, regardless of whether dev tools is open or not?

I've done quite a few things to trouble shoot this. I've added a query parameter that has seconds in it like this SO link says to do.

I've also added Profiling on DRF mentioned here.

What is weird that I don't see logs on the Django side after some API calls which means to me that Chrome is caching something.

I don't see this behaviour in Safari.

I also created a simple JQuery App and see this behaviour there, so I don't think its a React/Fetch problem.

Its really inconsistent, so its been very hard to troubleshoot.

EDIT

Here is my header showing cache control and I am still experiencing this:

HTTP/1.1 200 OK
Server: gunicorn/19.3.0
Date: Wed, 09 Nov 2016 16:39:07 GMT
Connection: close
Transfer-Encoding: chunked
Expires: Wed, 09 Nov 2016 16:39:07 GMT
Last-Modified: Wed, 09 Nov 2016 16:39:07 GMT
Allow: GET, POST, HEAD, OPTIONS
Cache-Control: no-cache, no-store, must-revalidate, max-age=0
Access-Control-Allow-Origin: *
Content-Type: application/json
Request Headers
view source
Community
  • 1
  • 1
dvreed77
  • 2,217
  • 2
  • 27
  • 42
  • 1
    Possible duplicate of [How to stop chrome from caching REST response from WebApi?](http://stackoverflow.com/questions/17755239/how-to-stop-chrome-from-caching-rest-response-from-webapi) – Heretic Monkey Nov 08 '16 at 22:11

1 Answers1

0

Straight from (How to stop chrome from caching REST response from WebApi?)

The answer is that Chrome does not like "Expires:Mon, 01 Jan 0001 00:00:00 GMT" (a fake date, basically).

I changed my date to be what they use in their Google API, and it worked:

Cache-Control:no-store, must-revalidate, no-cache, max-age=0
Content-Length:1897
Content-Type:application/json; charset=utf-8
Date:Fri, 19 Jul 2013 20:51:49 GMT
Expires:Mon, 01 Jan 1990 00:00:00 GMT
Pragma:no-cache
Server:Microsoft-IIS/8.0
Community
  • 1
  • 1
Valentin Roudge
  • 555
  • 4
  • 14