[ADP-369] HTTP Caching: ETag
Overview
The ETag
header is used for resource versioning and cache validation. For detailed information about ETag, please refer to ADP-128: ETag.
Procedures
- The client initiates the first GET request without any cache-related headers.
- The server returns the data with a calculated
ETag
. - The client requests the same GET again with
If-None-Match
. - The server checks the
If-None-Match
request against the latest data'sETag
.- return 200 if mismatch
- return 304 if matched
Guidance
- MAY supply ETag to cache the response
Implementation Detail
- There are two kinds of ETag:
Weak ETag
andStrong ETag
. - In
express
(nodejs web server framework), it would generate weak ETag by default; could generate strong ETag by changing the configuration - In
gin
(golang web server framework), ETag could be generated via a middleware.