Java Reference
In-Depth Information
stores it in its cache, and reloads it from the cache whenever it's needed rather than
requesting it from the remote server every time the logo is encountered. Several HTTP
headers, including Expires and Cache-control, can control caching.
By default, the assumption is that a page accessed with GET over HTTP can and should
be cached. A page accessed with HTTPS or POST usually shouldn't be. However, HTTP
headers can adjust this:
• An Expires header (primarily for HTTP 1.0) indicates that it's OK to cache this
representation until the specified time.
• The Cache-control header (HTTP 1.1) offers fine-grained cache policies:
max-age=[ seconds ] : Number of seconds from now before the cached entry
should expire
s-maxage=[ seconds ] : Number of seconds from now before the cached entry
should expire from a shared cache. Private caches can store the entry for longer.
public : OK to cache an authenticated response. Otherwise authenticated re‐
sponses are not cached.
private : Only single user caches should store the response; shared caches should
not.
no-cache : Not quite what it sounds like. The entry may still be cached, but the
client should reverify the state of the resource with an ETag or Last-modified
header on each access.
no-store : Do not cache the entry no matter what.
Cache-control overrides Expires if both are present. A server can send multiple
Cache-control headers in a single header as long as they don't conflict.
• The Last-modified header is the date when the resource was last changed. A client
can use a HEAD request to check this and only come back for a full GET if its local
cached copy is older than the Last-modified date.
• The ETag header (HTTP 1.1) is a unique identifier for the resource that changes
when the resource does. A client can use a HEAD request to check this and only come
back for a full GET if its local cached copy has a different ETag.
For example, this HTTP response says that the resource may be cached for 604,800
seconds (HTTP 1.1) or one week later (HTTP 1.0). It also says it was last modified on
April 20 and has an ETag, so if the local cache already has a copy more recent than that,
there's no need to load the whole document now:
HTTP/1.1 200 OK
Date: Sun, 21 Apr 2013 15:12:46 GMT
Server: Apache
Connection: close
Search WWH ::




Custom Search