Caching in HTTP

HTTP is used for distributed operating systems, where using the response caches, we can improve the performance. The HTTP/1.1 protocol includes a number of elements which is intended to make properly working of caching. Because these elements interact with each other and they are inextricable from other aspects of the protocol, it is useful to describe the HTTP caching design separately from the detailed description of response codes, methods, headers, etc.

The HTTP Caching is basically used to eliminate the need to send the request in many cases. It is also used to eliminate the need to send full responses in many other cases.

In HTTP, cache mechanisms are implicit directives to caches where expiration times and validators are specified by the server. For this purpose, we use the Cache-Control header.

The Cache-Control header is used to allow the client or the server to transmit a variety of directive in either request or response. The default caching algorithm is overridden by these directives. The directives of the caching are specified in a comma-separated list.

Example

  1. Cache-control: no-cache  

The client is using the cache request directives in its HTTP request as follows:

S.N.

Directive of Cache Request and Description

1

no-cache
It indicates that the response which is returned and cannot be used to satisfy a subsequent request to the same URL.

2

no-store
It indicates that the client will not store anything about the request of the client or the response of the server.

3

max-age = seconds
It is used to indicate that the client is willing to accept a response whose age is not greater than the time which is specified in seconds.

4

max-state [=seconds ]
It is used to indicate that the client is willing to accept a response that has exceeded its expiration time. It must not be expired by more than that time, if the seconds are given.

5

min-fresh= seconds
It is used to indicate that the client is willing to accept a response whose lifetime of freshness is not less than its current age plus, which is the specified time in seconds.

6

no-transform
It does not convert the entity-body.

7

only-if-cached
It does not retrieve new data. A document can be send by the cache only if it is in the cache and should not contact the origin-server to see if it exists a newer copy.

The directives of cache response can be used by the server in its HTTP response as follows:

S.N.

Directive of Cache Response and Description

1

public
It indicates that any cache may be cached the response.

2

private
It is used to indicate that some part of the response message or all the response message is intended for a single user. It must not be cached by a shared cache.

3

no-cache
It indicates that the response which is returned cannot be used to satisfy a subsequent request to the same URL.

4

no-store
It indicates that the client will not store anything about the request of the client or the response of the server.

5

no-transform
It does not convert the entity-body.

6

must-revalidate
It indicates that the cache must verify the stale document's status before using it, and expired ones should not be used.

7

proxy-revalidate
The proxy-revalidate directives and the must-revalidate directive have the same meaning, except that it does not apply to non-shared user agent caches.

8

max-age = seconds
It is used to indicate that the client is willing to accept a response whose age is not greater than the time which is specified in seconds.

9

s-maxage = seconds
The maximum age specified by the directives overrides the maximum age specified by either the Expires header or the max-age directives. The private cache always ignores the s-manage directives.