博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
http缓存_HTTP缓存
阅读量:2505 次
发布时间:2019-05-11

本文共 3067 字,大约阅读时间需要 10 分钟。

http缓存

Caching is a technique that can help network connections be faster, because the less things need to be transferred, the better.

缓存是一种可以帮助网络连接更快的技术,因为需要传输的内容越少越好。

Many resources can be very large, and be very expensive in terms of time and also actual cost (on mobile, for example) to retrieve.

许多资源可能非常大,并且在时间和检索的实际成本(例如在移动设备上)方面都非常昂贵。

There are different caching strategies that are made available by HTTP and used by browsers.

HTTP提供了不同的缓存策略,浏览器使用了它们。

没有缓存 (No caching)

First, the Cache-Control header can tell the browser to never use a cached version of a resource without first checking the ETag value (more on this later), by using the no-cache value:

首先,通过使用no-cache值, Cache-Control标头可以告诉浏览器从不使用资源的缓存版本,而无需先检查ETag值(稍后会详细介绍):

Cache-Control: no-cache

A more restrictive no-store option tells the browser (and all the intermediary network devices) the not even store the resource in its cache:

限制性更强的no-store选项告诉浏览器(和所有中间网络设备)甚至不将资源存储在其缓存中:

Cache-Control: no-store

If Cache-Control has the max-age value, that’s used to determine the number of seconds this resource is valid as a cache:

如果Cache-Control具有max-age值,则该值用于确定此资源作为缓存有效的秒数:

Cache-Control: max-age=3600

Expires标头 (The Expires header)

When an HTTP request is sent, the browser checks if it has a copy of that page in the cache, based on the URL you required.

发送HTTP请求后,浏览器会根据您所需的URL检查它是否在缓存中具有该页面的副本。

If there is, it checks the page for freshness.

如果存在,它将检查页面的新鲜度

A page is fresh if the value is less than the current datetime.

如果值小于当前日期时间,则页面是新鲜的。

The Expires header takes this form:

Expires标头采用以下形式:

Expires: Sat, 01 Dec 2018 16:00:00 GMT

有条件的GET (Conditional GET)

There are different ways to perform a conditional get. All are based on using the If-* request headers:

有多种执行条件获取的方法。 所有这些都基于使用If-*请求标头:

  • using If-Modified-Since and Last-Modified

    使用If-Modified-SinceLast-Modified

  • using If-None-Match and ETag

    使用If-None-MatchETag

使用If-Modified-SinceLast-Modified (Using If-Modified-Since and Last-Modified)

The browser can send a request to the server and instead of just asking for the page, it adds an , based on the Last-Modified header value it got from the currently cached page.

浏览器可以向服务器发送请求,而不仅仅是请求页面,它还基于从当前缓存的页面获取的Last-Modified标头值添加 。

This tells the server to only return a response body (the page content) if the resource has been updated since that date.

这告诉服务器如果自该日期以来资源已更新,则仅返回响应正文(页面内容)。

Otherwise the server returns a 304 Not Modified response.

否则,服务器将返回304 Not Modified响应。

使用If-None-MatchETag (Using If-None-Match and ETag)

The Web Server (depending on the setup, how page are served, etc) can send an .

Web服务器(取决于设置,如何提供页面等)可以发送 。

That is the identifier of a resource. Every time the resource changes, for example it’s updated, the ETag should change as well.

那是资源的标识符。 每当资源更改(例如更新)时,ETag也应更改。

It’s like a checksum.

就像校验和。

The browser sends an that contains one (or more) ETag value.

浏览器发送一个 ,其中包含一个(或多个)ETag值。

If none match, the server returns the fresh version of the resource, otherwise a 304 Not Modified response.

如果没有匹配项,则服务器返回资源的最新版本,否则返回304 Not Modified响应。

翻译自:

http缓存

转载地址:http://otqgb.baihongyu.com/

你可能感兴趣的文章
scala学习笔记-Actor(19)
查看>>
ADT+NDK+OpenCV 环境部署
查看>>
GDB调试实用命令
查看>>
Java 浮点运算
查看>>
线程安全
查看>>
Centos7安装tomcat8
查看>>
MySQL基本命令和常用数据库对象
查看>>
poj 1222 EXTENDED LIGHTS OUT(位运算+枚举)
查看>>
秘密:之所以不搞军事同盟,俄罗斯
查看>>
µC/OS-II版本升级指南
查看>>
hibernate中持久化对象的生命周期(三态:自由态,持久态,游离态 之间的转换)...
查看>>
postgres出现Server doesn't listen错误解决办法
查看>>
linux shell学习--awk练习
查看>>
敏捷开发一千零一问系列之十二:敏捷实施的步骤?
查看>>
TCP三次握手机制中的seq和ack
查看>>
java内部类的定义原则
查看>>
2017年11月26日 C#流&&窗体对话框
查看>>
endl与\n的区别
查看>>
进程和线程概念及原理
查看>>
Dubbo超时重试机制带来的数据重复问题
查看>>