200 OK (from cache)原因

2024-06-19 21:58
文章标签 200 原因 cache ok

本文主要是介绍200 OK (from cache)原因,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Meta标签中的http-equiv用来标记不可缓存或过期时间,但效果一般。而且代理缓存基本不访问HTML文档内容,所以尽量少用meta标签控制缓存。

Pragma: no-cache

Forces caches to submit the request to the origin server for validation before releasing a cached copy.

Pragma is not specified for HTTP responses .Use[a1]  Pragma only for backwards compatibility with HTTP/1.0 clients.

Cache-Control

used to specify directives for caching mechanisms in both, requests and responses. Caching directives are unidirectional(单向), meaning that a given directive in a request is not implying that the same directive is to be given in the response.

通用指令

Cache-Control: max-age=<seconds>

Specifies the maximum amount of time a resource will be considered fresh. Contrary to Expires, this directive is relative to the time of the request.

Cache-Control: no-cache(数据会被缓存)

Forces caches to submit the request to the origin server for validation before releasing a cached copy.

Cache-Control: no-store

The cache should not store anything about the client request or server response.

Cache-Control: no-transform

Cache-Control: max-age=<seconds>

request指令

Cache-Control: max-stale[=<seconds>]

Cache-Control: min-fresh=<seconds>

Cache-Control: only-if-cached

response指令

Cache-Control: must-revalidate

The cache must verify the status of the stale resources before using it and expired ones should not be used.

Cache-Control: public

Cache-Control: private

Cache-Control: proxy-revalidate

Cache-Control: s-maxage=<seconds>

Expires: <http-date>

The Expires header contains the date/time after which the response is considered stale.

Invalid dates, like the value 0, represent a date in the past and mean that the resource is already expired.

If there is a Cache-Control header with the "max-age" or "s-max-age" directive in the response, the Expires header is ignored.


 [a1]请求缓存和响应缓存有什么不同???

带条件请求和无条件请求

An unconditional request is made when the client browser does not have a cached copy of the resource available locally. In this case, the server is expected to return the resource with a HTTP/200 OK response. If the response’s headers permit it, the client may cache this response in order to reuse it later.
If the browser later needs a resource which is in the cache, but that response is expired (older than its max-age or past the Expires date), then the client will make a conditional request to the server to determine whether the previously cached response is still valid and should be reused. The conditional request contains an If-Modified-Since and/or If-None-Match header that indicates to the server what version of the content the browser already has in its cache. The server can indicate that the client’s copy is still fresh by returning HTTP/304 Not Modified headers with no body, or it can indicate that the client’s copy is stale by returning a HTTP/200 OK response with the new version of the resource.
In the first case (Normal-Refresh,F5), we will perform HTTP requests (conditional, if possible) to revalidate all of the resources on the page, regardless of freshness.In the second case (Super-Refresh,Ctrl+F5,强制刷新), we perform unconditional HTTP requests to redownload all of the content on the page, bypassing the cache altogether.

区分响应是来自原始服务器还是代理服务器?

The Date general-header field represents the date and time at which the message(报文) was originated.
The Age header contains the time in seconds the object has been in a proxy cache. If it is Age: 0, it was probably just fetched from the origin server; otherwise It is usually calculated as a difference between the proxy's current date and the Date general header included in the HTTP response.

200 OK (from cache) vs 304 Not Modified

200 OK (from cache)  是浏览器没有跟服务器确认,直接用了浏览器缓存,最快。一般在expires/max-age头部有效时不会发送请求。因为请求根本没有产生,所以在chrome下请求头部会显示:Provisional headers are shown
304 Not Modified 是浏览器和服务器确认了一次缓存的有效性,再使用缓存,多一次确认(If-Modified-Since/etag)请求。

为什么有"Last-Modified"时也会有200 OK from cache
不同的浏览器会根据不同的用户行为(刷新/强制刷新)对请求添加不同的头部,对响应采用不同的缓存策略。
When "Expires" and "Cache-Control" headers are not specified, but a "Last-Modified" header is specified, browsers have to guess at how long they should keep the document in cache. Some browsers do use algorithms that let the page remain in cache for a day or more.

这篇关于200 OK (from cache)原因的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1076259

相关文章

IDEA编译报错“java: 常量字符串过长”的原因及解决方法

《IDEA编译报错“java:常量字符串过长”的原因及解决方法》今天在开发过程中,由于尝试将一个文件的Base64字符串设置为常量,结果导致IDEA编译的时候出现了如下报错java:常量字符串过长,... 目录一、问题描述二、问题原因2.1 理论角度2.2 源码角度三、解决方案解决方案①:StringBui

部署Vue项目到服务器后404错误的原因及解决方案

《部署Vue项目到服务器后404错误的原因及解决方案》文章介绍了Vue项目部署步骤以及404错误的解决方案,部署步骤包括构建项目、上传文件、配置Web服务器、重启Nginx和访问域名,404错误通常是... 目录一、vue项目部署步骤二、404错误原因及解决方案错误场景原因分析解决方案一、Vue项目部署步骤

pip install jupyterlab失败的原因问题及探索

《pipinstalljupyterlab失败的原因问题及探索》在学习Yolo模型时,尝试安装JupyterLab但遇到错误,错误提示缺少Rust和Cargo编译环境,因为pywinpty包需要它... 目录背景问题解决方案总结背景最近在学习Yolo模型,然后其中要下载jupyter(有点LSVmu像一个

SpringBoot中的404错误:原因、影响及解决策略

《SpringBoot中的404错误:原因、影响及解决策略》本文详细介绍了SpringBoot中404错误的出现原因、影响以及处理策略,404错误常见于URL路径错误、控制器配置问题、静态资源配置错误... 目录Spring Boot中的404错误:原因、影响及处理策略404错误的出现原因1. URL路径错

在Rust中要用Struct和Enum组织数据的原因解析

《在Rust中要用Struct和Enum组织数据的原因解析》在Rust中,Struct和Enum是组织数据的核心工具,Struct用于将相关字段封装为单一实体,便于管理和扩展,Enum用于明确定义所有... 目录为什么在Rust中要用Struct和Enum组织数据?一、使用struct组织数据:将相关字段绑

Linux内存泄露的原因排查和解决方案(内存管理方法)

《Linux内存泄露的原因排查和解决方案(内存管理方法)》文章主要介绍了运维团队在Linux处理LB服务内存暴涨、内存报警问题的过程,从发现问题、排查原因到制定解决方案,并从中学习了Linux内存管理... 目录一、问题二、排查过程三、解决方案四、内存管理方法1)linux内存寻址2)Linux分页机制3)

Vue项目中Element UI组件未注册的问题原因及解决方法

《Vue项目中ElementUI组件未注册的问题原因及解决方法》在Vue项目中使用ElementUI组件库时,开发者可能会遇到一些常见问题,例如组件未正确注册导致的警告或错误,本文将详细探讨这些问题... 目录引言一、问题背景1.1 错误信息分析1.2 问题原因二、解决方法2.1 全局引入 Element

MySQL不使用子查询的原因及优化案例

《MySQL不使用子查询的原因及优化案例》对于mysql,不推荐使用子查询,效率太差,执行子查询时,MYSQL需要创建临时表,查询完毕后再删除这些临时表,所以,子查询的速度会受到一定的影响,本文给大家... 目录不推荐使用子查询和JOIN的原因解决方案优化案例案例1:查询所有有库存的商品信息案例2:使用EX

使用Spring Cache时设置缓存键的注意事项详解

《使用SpringCache时设置缓存键的注意事项详解》在现代的Web应用中,缓存是提高系统性能和响应速度的重要手段之一,Spring框架提供了强大的缓存支持,通过​​@Cacheable​​、​​... 目录引言1. 缓存键的基本概念2. 默认缓存键生成器3. 自定义缓存键3.1 使用​​@Cacheab

Spring中Bean有关NullPointerException异常的原因分析

《Spring中Bean有关NullPointerException异常的原因分析》在Spring中使用@Autowired注解注入的bean不能在静态上下文中访问,否则会导致NullPointerE... 目录Spring中Bean有关NullPointerException异常的原因问题描述解决方案总结