An example of this is the max-age directive which takes priority over any expiration time that is set in an Expires header.Ĭache-Control directives follow the syntax:Ĭache-Control: cache-request-directive, cache-response-directive The explicit directives in the Cache-Control header, take precedence over the implicit directives in both caching mechanisms. This is what the Cache-Control header is used for. To fully manage a cache, however, a server or client may need to provide explicit directives. These two cache mechanisms (validation and expiration) are implicit directives to a cache as to how resources should be updated. When the max-age directive is present in a response entity that is cached, the response entity is considered to be stale if its current age is greater than the max-age value. It's important to note that the max-age directive takes priority over an Expires header. The server specifies the expiration time of an entity by using an Expires header, or by including the max-age Cache-Control directive in a response. When the origin server specifies an explicit expiration time in the resource, a cache can check that expiration time and respond accordingly without having to contact the server first. If the validators do not match, the server sends the full information, but an extra round trip is eliminated by validating the cached entry up front.Įxpiration is the caching mechanism by which a client can entirely avoid making requests to the origin server. ![]() This mechanism saves a full server response, because the information does not need to be downloaded again. If the validators match, the server sends a 304 (Not Modified) response, and the client uses the cached entry. The server checks the validator in the request against the current validator for the resource. When the client makes a request for a resource, for which it has a cache entry, it includes the validator in the request. When a server generates a full response, it attaches a validator to it, which the client keeps with the cache entry for that resource. Validation is the process by which a cache entry is checked against the origin server (or against an intermediate cache) to validate that it is still usable. The HTTP/1.1 Protocol specifies two main caching mechanisms for achieving this: Validation and Expiration. ![]() It examines the issue of why caching is important, and provides recommendations for how to implement a cache and use caching mechanisms and Cache-Control directives in an application.Ĭaching significantly improves performance by eliminating as many requests to the server, and full server responses, as possible. This Best Practice Deep Dive looks at the caching mechanisms and Cache-Control directives that are specified in the HTTP/1.1 Protocol. Once cache control functionality is enabled, the server places directives in the Cache-Control field that can be used by the client to determine if a resource should be pulled from the client-side cache, or if it must be requested from the server. The HTTP 1.1 protocol supports cache management through the Cache-Control general-header of each request and response message. ![]() These savings can help keep a user beneath their data cap, keep their battery from draining as quickly, and improve the responsiveness of wireless networks that have limited capacity.ĭespite these benefits, some applications don't use Cache-Control directives at all, and many don't use caching mechanisms to their fullest extent. ![]() Enabling a cache, and making full use of Cache-Control directives, reduces the amount of data and data connections that are sent needlessly. When a file is cached, it is available immediately for reuse, which makes an application appear faster. By implementing a cache, and making full use of the caching mechanisms and Cache-Control directives that are available to your application, you can improve speed, energy usage, and user experience.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |