1.8 KiB
Caching
Every API implementation SHOULD return both the cache expiry information (Cache-Control HTTP header) and specific resource version information (ETag HTTP Header).
Cache-Control
Every API implementation's response SHOULD include information about cache-ability and cache expiration of the response.
ETag
Every API implementation's response to a cacheable request SHOULD include the ETag HTTP Header to identify the specific version of the returned resource.
Every API client SHOULD use If-None-Match HTTP header whenever it's performing a cacheable request. The value of If-None-Match should be the value of the ETag header stored from a previous request. The client MUST be ready to handle the 304 Not Modified response from the server to use the legal copy.
How ETag works
ETags are unique identifiers for a specific version of a resource found by a URL. They are used for cache validation, to quickly check for modifications.
A client requests a resource from the serve at a specific URI. The server responds with the specific ETag value in the HTTP ETag header field. This and the resource will be stored locally by the client. Subsequent requests from the client are done with the If-None-Match header, which now contains the ETag value from the previous request. The server now compares the values. If they are the same, it responds with HTTP Status Code 304 Not Modified. If not, the resource is sent.