Helping ordinary people create extraordinary websites!
GET OUR NEWSLETTER
Your Email:
 

Caching Tutorial

By Mark Nottingham
2007-12-22


How Web Caches Work

All caches have a set of rules that they use to determine when to serve a representation from the cache, if it’s available. Some of these rules are set in the protocols (HTTP 1.0 and 1.1), and some are set by the administrator of the cache (either the user of the browser cache, or the proxy administrator).

Generally speaking, these are the most common rules that are followed (don’t worry if you don’t understand the details, it will be explained below):

  1. If the response’s headers tell the cache not to keep it, it won’t.
  2. If the request is authenticated or secure, it won’t be cached.
  3. If no validator (an ETag or Last-Modified header) is present on a response, and it doesn't have any explicit freshness information, it will be considered uncacheable.
  4. A cached representation is considered fresh (that is, able to be sent to a client without checking with the origin server) if:
    • It has an expiry time or other age-controlling header set, and is still within the fresh period.
    • If a browser cache has already seen the representation, and has been set to check once a session.
    • If a proxy cache has seen the representation recently, and it was modified relatively long ago.
    Fresh representations are served directly from the cache, without checking with the origin server.
  5. If an representation is stale, the origin server will be asked to validate it, or tell the cache whether the copy that it has is still good.

Together, freshness and validation are the most important ways that a cache works with content. A fresh representation will be available instantly from the cache, while a validated representation will avoid sending the entire representation over again if it hasn’t changed.



Tutorial Pages:
» What’s a Web Cache? Why do people use them?
» Kinds of Web Caches
» Aren’t Web Caches bad for me? Why should I help them?
» How Web Caches Work
» How (and how not) to Control Caches
» Tips for Building a Cache-Aware Site
» Writing Cache-Aware Scripts
» Frequently Asked Questions
» Implementation Notes — Web Servers
» Implementation Notes — Server-Side Scripting
» References and Further Information


 | Bookmark
Related Tutorials:
» Setting Up Subversion for Development on Windows
» Stylize Your Digg Count
» Installing Apache on Windows
» Ecommerce Imagery: Persuading with Pictures
» Customizable Websites - The Definitive Guide
» 7 Usability Guidelines for Websites on Mobile Devices

Advertise with Us!


Tutorials Scripts Web Hosting Developer Manuals
Resources