问题
REST allows to use etags for caching.
Similarly browser supports caching unless headers like the following are set -> maxage, expires, cache-control: private
What is difference between etags and the above mentioned caching approach?
回答1:
What is difference between etags and normal browser provided caching?
I think you will find that they are very different ideas.
In HTTP, caching semantics are defined by RFC 7234: Caching.
Entity tags are defined by RFC 7232: Conditional Requests
An entity-tag is an opaque validator for differentiating between multiple representations of the same resource, regardless of whether those multiple representations are due to resource state changes over time, content negotiation resulting in multiple representations being valid at the same time, or both.
Validator semantics are used to support preconditions. Two common use cases:
In a "conditional GET" scenario, the client will send validators (via an If-None-Match header) that identify the representations that are already available locally. In the case where the validator matches the current representation, the server can limit the response to only sending refreshed metadata (headers) rather than re-sending the representation of the resource.
In a "conditional PUT" scenario, the client will send a validator (via an If-Match header) identifying the version of the resource that the request is intended to apply to.
the client intends this precondition to prevent the method from being applied if there have been any changes to the representation data.
Think "optimistic locking" - we're trying to avoid the "lost edit problem" by ensuring that there haven't been any other changes to the resource since the server originally told us about it.
来源:https://stackoverflow.com/questions/62212558/what-is-difference-between-etags-and-normal-browser-provided-caching