Monday, 19 May 2014

HTTP - Caching

Filled under:

Post By: Hanan Mannan
Contact Number: Pak (+92)-321-59-95-634
-------------------------------------------------------

HTTP - Caching
HTTP is typically used for distributed information systems, where performance can be improved by the use of response caches. The HTTP/1.1 protocol includes a number of elements intended to make caching work.
The goal of caching in HTTP/1.1 is to eliminate the need to send requests in many cases, and to eliminate the need to send full responses in many other cases.
The basic cache mechanisms in HTTP/1.1 are implicit directives to caches where server-specifies expiration times and validators. We use the Cache-Control header for this purpose.
The Cache-Control header allows a client or server to transmit a variety of directives in either requests or responses. These directives typically override the default caching algorithms. The caching directives are specified in a comma-separated list. For example:
Cache-control: no-cache
There are following important cache request directives which can be used by the client in its HTTP request:
S.N.Cache Request Directive and Description
1no-cache
A cache must not use the response to satisfy a subsequent request without successful revalidation with the origin server.
2no-store
The cache should not store anything about the client request or server response.
3max-age = seconds
Indicates that the client is willing to accept a response whose age is no greater than the specified time in seconds.
4max-stale [ = seconds ]
Indicates that the client is willing to accept a response that has exceeded its expiration time. If seconds are given, it must not be expired by more than that time.
5min-fresh = seconds
Indicates that the client is willing to accept a response whose freshness lifetime is no less than its current age plus the specified time in seconds.
6no-transform
Do not convert the entity-body.
7only-if-cached
Do not retrieve new data. The cache can send a document only if it is in the cache, and should not contact the origin-server to see if a newer copy exists.
There are following important cache response directives which can be used by the server in its HTTP response:
S.N.Cache Request Directive and Description
1public
Indicates that the response may be cached by any cache.
2private
Indicates that all or part of the response message is intended for a single user and must not be cached by a shared cache.
3no-cache
A cache must not use the response to satisfy a subsequent request without successful revalidation with the origin server.
4no-store
The cache should not store anything about the client request or server response.
5no-transform
Do not convert the entity-body.
6must-revalidate
The cache must verify the status of stale documents before using it and expired one should not be used.
7proxy-revalidate
The proxy-revalidate directive has the same meaning as the must- revalidate directive, except that it does not apply to non-shared user agent caches.
8max-age = seconds
Indicates that the client is willing to accept a response whose age is no greater than the specified time in seconds.
9s-maxage = seconds
The maximum age specified by this directive overrides the maximum age specified by either the max-age directive or the Expires header. The s-maxage directive is always ignored by a private cache.

0 comments: