Skip to content

Instantly share code, notes, and snippets.

@hjr3
Created October 17, 2012 00:34
Show Gist options
  • Save hjr3/3903025 to your computer and use it in GitHub Desktop.
Save hjr3/3903025 to your computer and use it in GitHub Desktop.
HTTP examples for Cache-Control

Request for member resource

Request

GET /member/1234
Host: www.example.com

Response

HTTP/1.1 200 OK
Date: Tue, 16 Oct 2012 23:57:52 GMT
Expires: Wed, 17 Oct 2012 23:57:52 GMT

{"email":"[email protected]", "password":"12345"}
  • The response expires in 24 hours

Update the email address of the member resource

Request

POST /member/1234
Host: www.example.com

{"email":"[email protected]"}

Response

HTTP/1.1 200 OK

{"email":"[email protected]", "password":"12345"}

Request from the proxy a new version of the object

Request

GET /member/1234
Host: www.example.com
Cache-Control: max-age=0

Response

HTTP/1.1 200 OK
Date: Tue, 17 Oct 2012 00:10:12 GMT
Expires: Wed, 18 Oct 2012 00:10:12 GMT

{"email":"[email protected]", "password":"12345"}
  • The presence of the Cache-Control header specifying max-age=0 in the request should force the proxy to revalidate with the origin server per RFC 2616

Same client makes a later request for the member resource

Request

GET /member/1234
Host: www.example.com

Response

HTTP/1.1 200 OK
Date: Tue, 17 Oct 2012 03:05:03 GMT
Expires: Wed, 18 Oct 2012 00:10:12 GMT

{"email":"[email protected]", "password":"12345"}
  • The request does not specify the Cache-Control header
  • The response has the same Expires header value as the previous response (cached at the edge)
  • The response has a Date header value that is older than the Expires header
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment