Sunday, September 10, 2006

Old style cache control

What if you want your page to be checked once per day, whatever are browser settings? Or every time the page is visited, although this is a bad idea for statics? HTTP/1.0 has the Expires clause, that allows web servers to specify a date/time after which the entity should be considered out of date and checked by browsers. Using Expires  the web designer can control how fresh each entity is, instead of relying on browser's and proxie's good will — and still using cache advantages.

Now imagine two users sharing their ISP's proxy. As result of one happy coincidence they are going to visit a new page with expiration set by the server; first request is made by Mr.Fox:

GET /cache/static2/testpage.html HTTP/1.1
User-Agent: Mozilla/5.0 Gecko/20060410 Firefox/1.0.8

HTTP/1.1 200 OK
Last-Modified: Fri, 08 Sep 2006 20:09:37 GMT
ETag: "4a1f-4b9-c99ec240"
Expires: Sun, 10 Sep 2006 06:12:57 GMT
X-Cache: MISS from localhost
(show all)

The proxy never seen that page, so will fetch it from the server or other proxy and send it to the browser, reporting (or omitting) a "MISS". While the page is considered fresh Mr.Fox can navigate anywhere and, if returns to the page, will get it from his own cache. More, if Mr.Smith requests the same page in that period of time he will get it from proxy cache:

GET /cache/static2/testpage.html HTTP/1.0
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0)

HTTP/1.0 200 OK
Last-Modified: Fri, 08 Sep 2006 20:09:37 GMT
ETag: "4a1f-4b9-c99ec240"
Expires: Sun, 10 Sep 2006 06:12:57 GMT
X-Cache: HIT from localhost
(show all)

Notice that, if the page's period of validity is 60 seconds and Mr.Smith visits it 40 seconds after Mr.Fox, Mr.Smith's browser will see it as valid for 20 seconds. After the page is considered out of date, if someone using the proxy tries to access the page, proxy will check it with server and the answer will be available to any user:

GET /cache/static2/testpage.html HTTP/1.0
If-Modified-Since: Fri, 08 Sep 2006 20:09:37 GMT
If-None-Match: "4a1f-4b9-c99ec240"
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0)

HTTP/1.0 304 Not Modified
ETag: "4a1f-4b9-c99ec240"
Expires: Sun, 10 Sep 2006 06:20:03 GMT
X-Cache: MISS from localhost
(show all)

0 Comments:

Post a Comment

<< Home