News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

What happens when the cache entry expires?

Started by sukishan, Aug 22, 2009, 06:38 PM

Previous topic - Next topic

sukishan

If the browser requests an object that's in the browser cache but has expired, the object may still be valid. The browser can then check with the server again to see if the cached entry is still usable. It does this by including an If-Modified-Since header in the request. This is called validating the cache entry. If the cached entry in the browser is still the same, it's unnecessary for the server to resend the unchanged item. If the server finds instead that the content has changed—that is, it's no longer valid—a full response or refreshed page is returned to the browser.

An example sequence of events for a conditional request is shown below:
The browser navigates to a page and makes a HTTP request.
The server returns a successful response with the Cache-Control header and a Last-Modified in the response.
The browser stores the content in the cache.
Time elapses; the browser navigates to the same page again and finds that the content has expired in its cache.
The browser makes a conditional request to the server with an If-Modified-Since cache validator. The same GMT time from the Last-Modified header of the original response (point 2.) is used in the conditional request here.

If the server finds that the content is the same, it responds with a status code 304, indicating that the content hasn't been modified. The browser can then reuse the cached item, saving on download energy.

There is a small overhead when using conditional requests: when using the If-Modified-Since header in the browser's request, and the Cache-Control directive with Last-Modified header in the server's response. But when you compare that to sending the entire response, you're looking at a significant saving in network traffic.
A good beginning makes a good ending