HTTP is a protocol that highly depends on header usage. The controlling cache is one of the operations managed by the headers. Cache-Control header with the various values is the most basic caching system. Along with the Cache-Control header; Etag, Last-Modified, and Vary are used for caching.
MerlinCDN can be used with your origin’s Cache-Control header value to manage the caching mechanism or with Page Rules feature, the cache-control header can be overridden. These two options can be used hybrid for different contents.
Cache-Control Header Values
To manage the caching conditions Cache-Control header can take a lot of different values alongside multiple values at once.
No-store
This content can not be stored. All the requests are responded by the origin.
No-cache
This content can be stored but can not be served without revalidation. For all the requests a revalidation request is sent to the origin.
Private and Public
Private value bypasses the shared cache. This content can only be stored in the user’s browser cache.
Public value allows caching in all the layers. Both shared cache and browser can store the data. If there is no indication (no-cache, no-store, private or public) this value is assumed as public.
Max-age
This value can be used with private and public values to indicate the cache time. The content is stored for the time given in the value (in seconds). Example usage:
Cache-Control: public, max-age=300
S-max-age
Similar to max-age this value indicates the cache time. But it indicates the time for shared caches. It can be used with max-age to differ the cache time of browser and shared cache. Example usage:
Cache-Control: public, max-age=300, s-max-age=6000
The content will be stored in the browser for 300 seconds but in the shared cache it will be stored for 6000 seconds.
Must-revalidate
This value applies when a cache is expired. After cache expires, the content can be served and validated or updated after for the speed concerns. If the must-revalidate value is assigned the content can not be served before validation.
Proxy-revalidate
Similar to must-revalidate it indicates the validation of the content but proxy-revalidate applies this for only shared caches. Local caches are not affected by this value.
No-transform
It forbids any changes to the response (such as minimizing data for storing and slow connection concerns) and headers Content-Encoding, Content-Range, or Content-Type.
Stale-while-revalidate
This value applies when cache is expired. This value indicates while the content is being validated, the stale cache will be served. Time value indicates how long the stale cache will be served.
Stale-if-error
This value applies when cache is expired. This value indicates while the content is being validated if an error occurs, the stale cache will be served. Time value indicates how long the stale cache will be served.
Pragma
Cache-Control header is used in HTTP/1.1. In HTTP/1.0, to manage to cache Pragma header is used. Compared to Cache-Control, Pragma is very basic and gives a little control over the cache. The pragma can only take the no-cache value which does the same configuration as the Cache-control header value.
No-cache
This content can be stored but can not be served without revalidation. For all the requests a revalidation request is sent to the origin.
Pragma does not have the same functionality as the Cache-control so it must be used only for back compatibility.
Validation
Validation is the process that determines whether the cached content is changed or not. After the cache TTL expires, the server requests the content again and controls whether it is changed or not. Controlling the content saves bandwidth since it is not served if it is not necessary.
E-tag Header and values
E-tag is a validation tool. E-tag header value is unique for the content and this value changes if the content changes. To validate the content, a request to the server is sent with If-None-Match header that contains the Etag value. If the content is unchanged server will respond with a status code 304 (Not modified) without a body (saving on bandwidth) and the Cache TTL will reset.
Last-Modified Header and Values
Last Modified is used for validation just as Etag. Last-Modified indicates the date the content is changed. Comparing the Last-Modified value of the cache by sending a request with If-Modified-Since header the cache is validated. If the content is not changed, the server returns a 304 (Not Modified) request with no request body (saving on bandwidth).
Age Header and Values
Age header indicates the time that content is stored in the cache in seconds.
Comments
Please sign in to leave a comment.