有关ETAG和缓存控制标头的问题

发布于 2025-02-05 18:19:49 字数 609 浏览 3 评论 0原文

我正在尝试自定义缓存策略。
不适合我。

因为默认设置 强>
请检查我的理解是否正确。


首先,我的响应数据不经常变化。 但偶尔会改变。

这是我的计划。

也许我应该每次重新估计。因此,我需要设置我的CACH-CORTORL这样。

Cache-Control: public max-age=0 must-revalidate

我想,通过这种方式,我的数据将存储在客户端浏览器
中 并且浏览器将始终发送检查值是新的请求。

在服务器上,我将编写代码来处理以下行中写的内容。

  1. 首先,将ETAG放在响应标头上。

  2. 第二,如果如果不匹配值来自请求标题,我将其与我的服务逻辑进行比较以检查值是否最新。

  3. 如果如果不匹配值是最新的,我只是在响应中编写304并发送。

  4. ,否则,我只是正常响应数据。具有新的ETAG值。

I am trying to customize cache strategy.
because default setting is not fit on me ... Serviced by (Vercel).

I am unfamiliar with the cache setting through the http header, so I would like to ask for help.
Please check if my understanding is correct.


First of all, my response data doesn't change often.
But occasionally it changes.

Here is my plan.

Maybe i should revalidate every time. so i need to set my Cache-Control like this.

Cache-Control: public max-age=0 must-revalidate

I guess, with this way, my data will be stored in the client browser
and the browser will always send request that check the value is new.

And on the server, i'll write code to handle the things written in the lines below.

  1. First, set Etag on response header.

  2. Second, if the If-None-Match value comes from the request header, I compare it with my service logic to check whether the value is up to date.

  3. If the If-None-Match value is up to date, I just write 304 in the response and send it.

  4. And otherwise, I just respond with the data normally. with the new Etag value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文