跳至内容 跳至搜索

表示请求的 HTTP Cache-Control 标头,提供访问各种缓存控制指令的方法。参考:www.rfc-editor.org/rfc/rfc9111.html#name-request-directives

方法
M
N
O

Attributes

[R] max_age

返回 max-age 指令的值。此指令表示客户端愿意接受一个年龄不超过指定秒数的响应。

[R] max_stale

返回 max-stale 指令的值。当 max-stale 存在并带有一个值时,返回该整数值。当 max-stale 存在但不带值时,返回 true(表示不限制陈旧度)。当 max-stale 不存在时,返回 nil。

[R] min_fresh

返回 min-fresh 指令的值。此指令表示客户端愿意接受一个新鲜度寿命不小于其当前年龄加上指定秒数的响应。

[R] stale_if_error

返回 stale-if-error 指令的值。此指令表示在检查新鲜响应失败并出现错误的情况下,客户端愿意接受一个陈旧的响应,其时间限制为指定的秒数。

类公共方法

new(cache_control_header)

# File actionpack/lib/action_dispatch/http/cache.rb, line 75
def initialize(cache_control_header)
  @only_if_cached = false
  @no_cache = false
  @no_store = false
  @no_transform = false
  @max_age = nil
  @max_stale = nil
  @min_fresh = nil
  @stale_if_error = false
  parse_directives(cache_control_header)
end

实例公共方法

max_stale?()

如果 max-stale 指令存在(无论是否带值),则返回 true。

# File actionpack/lib/action_dispatch/http/cache.rb, line 127
def max_stale?
  !@max_stale.nil?
end

max_stale_unlimited?()

如果 max-stale 指令存在但未带值(表示不限制陈旧度),则返回 true。

# File actionpack/lib/action_dispatch/http/cache.rb, line 132
def max_stale_unlimited?
  @max_stale == true
end

no_cache?()

如果 no-cache 指令存在,则返回 true。此指令表示缓存不得在没有与源服务器成功验证的情况下使用响应来满足后续请求。

# File actionpack/lib/action_dispatch/http/cache.rb, line 98
def no_cache?
  @no_cache
end

no_store?()

如果 no-store 指令存在,则返回 true。此指令表示缓存不得存储请求或响应的任何部分。

# File actionpack/lib/action_dispatch/http/cache.rb, line 105
def no_store?
  @no_store
end

no_transform?()

如果 no-transform 指令存在,则返回 true。此指令表示缓存或代理不得转换载荷。

# File actionpack/lib/action_dispatch/http/cache.rb, line 111
def no_transform?
  @no_transform
end

only_if_cached?()

如果 only-if-cached 指令存在,则返回 true。此指令表示客户端只希望获得存储的响应。如果不存在有效的存储响应,服务器应响应 504(网关超时)状态。

# File actionpack/lib/action_dispatch/http/cache.rb, line 91
def only_if_cached?
  @only_if_cached
end