📘
Deuterium Wiki
  • Hello
  • Linux
    • cmd
      • du: 显式文件大小
      • seq: 生成序列
      • cat: 连接
      • cp: 复制
      • cd: 切换目录
      • mv: 移动
    • awk
      • 执行awk脚本
      • 删除空行
      • 个数统计
      • 文件的交集
      • 文件的差集
    • mysql
      • 删除重复数据
      • 导出数据不带标题
  • Reading
    • Novel
      • 《基督山伯爵》人物关系
    • Awesome CS Books
      • csapp-3e-homework-solution
        • 1. A Tour of Computer Systems
        • 2. Representing and Manipulating Information
          • 2.55 Compile and Run
          • 2.56 Another Try
          • 2.57 More show Procedures
          • 2.58 Check Little-Endian
          • 2.59 Bit Expressions
          • 2.60 Replace Byte
          • 2.61 More Bit Expressions
          • 2.62 Check Arithmetic Right Shift
          • 2.63 Logic & Arithmetic Right Shift
          • 2.64 Any Odd One
          • 2.65 Odd Ones
          • 2.66 Leftmost One
          • 2.67 Int Size is 32
          • 2.68 Lower One Mask
          • 2.69 Rotate Left
          • 2.70 Fits Bits
          • 2.71 Xbyte
          • 2.72 Copy Int
          • 2.73 Saturating Add
          • 2.74 Sub OK
          • 2.75 Unsigned High Prod
          • 2.76 calloc
          • 2.77 Multiple By Shifts
          • 2.78 Divide Power 2
          • 2.79 Mul3div4
          • 2.80 Three Fourths
          • 2.81 Generate Bits
          • 2.82 Signed and Unsigned
          • 2.83 Binary Floating Value
          • 2.84 Float Le
          • 2.85 Floating Point I
          • 2.86 Extend Precision
          • 2.87 Floating-Point II
          • 2.88 Floating-Point III
          • 2.89 Floating-Point IV
          • 2.90 fpwr2
          • 2.91 π
          • 2.92 Float Negate
          • 2.93 Float Absval
          • 2.94 Float Twice
          • 2.95 Float Half
          • 2.96 Float f2i
          • 2.97 Float i2f
        • 3. Machine-Level Representation of Programs
          • 3.58 Decode
          • 3.59 128-bit Multiply
          • 3.60 For Loop
          • 3.61 Conditional Data Transfer
          • 3.62 Switch I
          • 3.63 Switch II
          • 3.64 Multiple Dimension Array I
          • 3.65 Multiple Dimension Array II
          • 3.66 Multiple Dimension Array III
          • 3.67 Caller and Callee
          • 3.68 Alignment
          • 3.69 Struct
          • 3.70 Union
          • 3.71 fgets
          • 3.72 Variable-Size Stack
          • 3.73 Find Range I
          • 3.74 Find Range II
          • 3.75 Complex
      • tcpv1
        • ch01: Introduction
        • ch02: Link Layer
        • ch03: Internet Protocol
        • ch04: Address Resolutin Protocol
        • ch05: Reverse Address Resolution Protocol
        • ch06: Internet Control Message Protocol
        • ch07: Ping Program
        • ch08: Traceroute Program
        • ch09: IP Routing
        • ch10: Dynamic Routing Protocols
        • ch11: User Datagram Protocol
        • ch12: Broadcasting and Multicasting
        • ch13: Internet Group Management Protocol
        • ch14: The Domain Name System
        • ch15: Trivial File Transfer Protocol
        • ch16: Boostrap Protocol
        • ch17: Transmission Control Protocol
        • ch18: TCP Connection Establishment and Termination
        • ch 19: TCP Interactive Data Flow
        • ch20: TCP Bulk Data Flow
      • http
        • ch01: Overview of HTTP
        • ch02: URLs and Resources
        • ch03: HTTP Messages
        • ch04: Connection Management
        • ch05: Web Servers
        • ch06: Proxies
        • ch07: Caching
        • ch08: Integration Points
        • ch09: Web Robots
        • ch10: HTTP-NG
        • ch11: Client Identification and Cookies
        • ch12: Basic Authentication
        • ch13: Digest Authentication
        • ch14: Secure HTTP
        • ch15: Entities and Encodings
        • ch16: Internationalizated
        • ch17: Content Negotiation and Transcoding
        • ch18: Web Hosting
        • ch19: Publishing Systems
        • ch20: Redirections and Load Balancing
        • ch21: Logging and Usage Tracking
    • 提升认知
      • 《为什么需要生物学思维》
      • 《大话西方艺术史》
  • Mathematics
Powered by GitBook
On this page
  • 1. The Benefits of Caches
  • 2. Hits and Misses
  • 2.1 Revalidations
  • 2.2 Hit Rate & Byte Hit Rate
  • 3. Cache Topologies
  • 4. Cache Processing Steps
  • 5. Keeping Copies Fresh
  • 5.1 Document Expiration
  • 5.2 Expiration Dates and Ages
  • 5.3 Server Revalidation
  • 5.4 Revalidation with Conditional Methods
  • 6. Controlling Cachability
  • 6.1 No-Cache and No-Store Response Headers
  • 6.2 Max-Age Response Headers
  • 6.3 Expires Response Headers
  • 6.4 Must-Revalidate Response Headers
  • 6.5 Heuristic Expiration
  • 7. Detailed Algorithms

Was this helpful?

  1. Reading
  2. Awesome CS Books
  3. http

ch07: Caching

Previousch06: ProxiesNextch08: Integration Points

Last updated 4 years ago

Was this helpful?

7.缓存

1. The Benefits of Caches

  • reduce redundant data transfers.

  • reduce network bottlenecks.

  • reduce demand on origin servers.

  • reduce distance delays.

2. Hits and Misses

2.1 Revalidations

  • Revalidate hit: HTTP 304 Not Modified response.

  • Revalidate miss: HTTP 200 OK.

  • Object deleted: HTTP 404 Not Found.

2.2 Hit Rate & Byte Hit Rate

  • Hit rate: describes how many web transactions are kept off the outgoing network.

  • Byte hit rate: describes how many bytes are kept off the Internet.

3. Cache Topologies

Private caches and public caches.

Caches can also be built into hierarchy.

4. Cache Processing Steps

  1. Receiving: Cache reads the arriving requests message from the network.

  2. Parsing: Cache parses the message, extracting the URL and headers.

  3. Lookup: Cache checks if a local copy is available and, if not, fetches a copy (and stores it locally).

  4. Freshness check: Cache checks if cached copy is fresh enough and, if not, asks server for any updates.

  5. Response creation: Cache makes a response message with the new headers and cached body.

  6. Sending: Cache sends the response back to the client over the network.

  7. Logging: Optionally, cache creates a log file entry describing the transaction.

Flow chart:

5. Keeping Copies Fresh

Document expiration and server revalidation.

5.1 Document Expiration

HTTP lets an origin server attach an "expiration date" to each document, using special HTTP Cache-Control and Expires headers.

5.2 Expiration Dates and Ages

Header

Description

Cache-Control: max-age

The max-age defines maximum age of the document(in seconds).

Expires

Specifies an absolute expiration date. If the expiration date is in the past, the document is no longer fresh.

5.3 Server Revalidation

  • If revalidation shows the content has changed, the cache gets a new copy of the document, stores it in place of the old data, and sends the document to the client.

  • If revalidation shows the content has not changed, the cache gets a new headers, including a new expiration date, and updates the headers in the cache.

5.4 Revalidation with Conditional Methods

Two conditional headers used in cache revalidation:

Header

Description

If-Modified-Since: \

Perform the requested method if the document has been modified since the specified date. This is used in conjunction with the Last-Modified server response header, to fetch content only if the content has been modified from the cached version.

If-None-Match: \

Instead of matching on last-modified date, the server may provide special tags on the document that act like serial numbers. The If-None-Match header performs the requested method if the cached tags differ from the tags in the server's document.

If-Modified-Since:

If-None-Match:

6. Controlling Cachability

A server can define how long a document can be cached before it expires. In decreasing order of priority, the server can:

  • Attach a Cache-Control: no-store header to the response.

  • Attach a Cache-Control: no-cache header to the response.

  • Attach a Cache-Control: must-revalidate header to the response.

  • Attach a Cache-Control: max-age header to the response.

  • Attach an Expires date header to the response.

  • Attach no expiration information, letting the cache determine tis own heuristic expiration date.

6.1 No-Cache and No-Store Response Headers

  • No-Store: forbids a cache from making a copy of the response.

  • No-Cache: a response can actually be stored in the local cache storage. It just cannot be served from the cache to the client without first revalidating the freshness with the origin server.

6.2 Max-Age Response Headers

The Cache-Control: max-age header indicates the number of seconds since it came from the server for which a document can be considered fresh.

s-maxage applies only to shared caches.

Cache-Control: max-age=3600
Cache-Control: s-maxage=3600

Servers can request that caches either not cache a document or refresh on every access by setting the maximum aging to zero:

Cache-Control: max-age=0
Cache-Control: s-maxage=0

6.3 Expires Response Headers

Deprecated

Use an absolute time.

6.4 Must-Revalidate Response Headers

Cache-Control: must-revalidate

6.5 Heuristic Expiration

LM-Factor algorithm: guess a fresh time.

7. Detailed Algorithms

Age: