Ok, I’m confused. I’m trying to send back the magic headers from my server that will prevent a client from hitting the server again until a resource is stale.
I understand how ETag or Last-Modified works (Validation) – the client will ALWAYS still hit the server, and the server needs to validate the date or etag against the current value to know whether to bother serving up a new one.
Cache-Control and Expires, however, I don’t think I understand. I’ve set the following:
Cache-Control: max-age=86400, must-revalidate
No matter what I do, my client (my browser, curl, NSURLConnection) always hits the server again on the second request. Is this a client thing? What headers should I send back to get the client to use it’s private cache for a certain length of time?
As Nathan hints at in his answer, clients can issue a subsequent request with an
If-Modified-Sinceheader to determine whether or not their cache is stale. If the client receives a304 Not Modifiedresponse, it will serve the content out of the local cache.According to RFC 2616 (the HTTP 1.1 specification), the presence of
must-revalidatewithin theCache-controlheader forces clients to re-check their cache’s status with the originating server prior to serving out of the cache.