How can I detect when the client hits F5 / refresh? Are there any headers sent to the server to indicate this that I can grab? I'm doing some server-side caching and I'd like to automatically expire the cache when a refresh is detected. Thanks.
Asked
Active
Viewed 439 times
2 Answers
1
ETags may be a more correct solution, but simply looking for the Cache-Control
header is enough, since the browser will use it to indicate caches should not be used.
Chrome sends Cache-Control: max-age=0
, but some other browsers send Cache-Control: no-cache
. You may want to expire cache on any cache control header you don't recognize.
Or even:
if any(i.lower().startswith('cache-control:') for i in self.headers): #...

otus
- 5,572
- 1
- 34
- 48
0
I'd look at ETags and conditional cache validation requests.
If the browser sends a If-None-Match
header they had a cached copy and want to see if they can reuse it. Instead of sending a 304 Not Modified you instead clear your cache, produce a full 200 OK response and set a new ETag header.

Martijn Pieters
- 1,048,767
- 296
- 4,058
- 3,343