Current Date: Mon, Sep 20, 2021 7:51 AM

Caching in HTTP

Caching in HTTP

HTTP is typically used for distributed information systems, where performance can be enhanced by using response caches. The HTTP / 1.1 protocol includes a number of elements that are intended to do caching work.

The goal of caching in HTTP / 1.1 is to calculate the need to send requests in many cases, and to compute the need to send complete responses in many other cases.

The basic caching technique in HTTP / 1.1 is to include directives to caches where the server determines the expiration date and time. We use the field Cache-Control for this purpose.

School Cache-Control allows a client or server to transmit various directives in either requests or responses. These directives are characterized by a higher priority than by default caching algorithms. Cached directives are identified in a comma-separated list. For example:

Cache-control: no-cache

The following are the caching request directives that can be used by the client in its HTTP request:

Instructions for caching requirements Description no-cache

A cache must not use a response to satisfy a follow-up request without successfully recertifying with the original server.

no-store

The cache should not hold anything about the client request or server response.

max-age = (in seconds)

Indicates that the client is trying to accept a response whose duration is not greater than the specified time in seconds (s).

max-stale [= giây]

Indicates that the client is trying to accept a response that has exceeded its expiration time. If the number of seconds is provided, it must not be expired by more than that time.

min-fresh = seconds

Indicates that the client is trying to accept a response whose healthy lifespan is no less than its current age plus the specified time in seconds.

no-transform

Does not convert the object body.

only-if-cached

Do not get new data. The cache can send a document only when it is in the cache, and it is not advisable to contact the original server to see if a newer copy exists.

The following caching response directives can be used by the Server in its HTTP response:

Cache response instructions Description public

Indicates that the response can be cached by any cache.

private

Indicates that all or part of the response message is treated as for a single user and must not be cached by a shared cache.

no-cache

A cache must not use a response to satisfy a follow-up request without successfully recertifying with the original server.

no-store

The cache should not store anything about the Client request or Server response.

no-transform

Does not convert the object body.

must-revalidate

The cache must verify the status of stale documents before using it, and expired documents should not be used.

proxy-revalidate

The authorization re-authentication directive has the same meaning as the must-revalidate directive, except it doesn't apply to non-shared user agent caches.

max-age = seconds

Indicates that the client is trying to accept a request whose age is not greater than the specified time in seconds.

s-maxage = seconds

The maximum age specified by this directive exceeds the maximum age specified by either the max-age directive or the Expires Header. The s-maxage directive is always ignored by a private memory.

According to Tutorialspoint

Previous post: Header fields in HTTP

Next article: URL encoding in HTTP