What is difference between etags and normal browser provided caching?

廉价感情. 提交于 2021-02-11 17:38:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!