class ActionDispatch::Http::Cache::Request::CacheControlDirectives
Represents the HTTP Cache-Control header for requests, providing methods to access various cache control directives Reference: www.rfc-editor.org/rfc/rfc9111.html#name-request-directives
Attributes
Returns the value of the max-age directive. This directive indicates that the client is willing to accept a response whose age is no greater than the specified number of seconds.
Returns the value of the max-stale directive. When max-stale is present with a value, returns that integer value. When max-stale is present without a value, returns true (unlimited staleness). When max-stale is not present, returns nil.
Returns the value of the min-fresh directive. This directive indicates that the client is willing to accept a response whose freshness lifetime is no less than its current age plus the specified time in seconds.
Returns the value of the stale-if-error directive. This directive indicates that the client is willing to accept a stale response if the check for a fresh one fails with an error for the specified number of seconds.
Public Class Methods
Source
# File 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
Public Instance Methods
Source
# File lib/action_dispatch/http/cache.rb, line 127 def max_stale? !@max_stale.nil? end
Returns true if max-stale directive is present (with or without a value)
Source
# File lib/action_dispatch/http/cache.rb, line 132 def max_stale_unlimited? @max_stale == true end
Returns true if max-stale directive is present without a value (unlimited staleness)
Source
# File lib/action_dispatch/http/cache.rb, line 98 def no_cache? @no_cache end
Returns true if the no-cache directive is present. This directive indicates that a cache must not use the response to satisfy subsequent requests without successful validation on the origin server.
Source
# File lib/action_dispatch/http/cache.rb, line 105 def no_store? @no_store end
Returns true if the no-store directive is present. This directive indicates that a cache must not store any part of the request or response.
Source
# File lib/action_dispatch/http/cache.rb, line 111 def no_transform? @no_transform end
Returns true if the no-transform directive is present. This directive indicates that a cache or proxy must not transform the payload.
Source
# File lib/action_dispatch/http/cache.rb, line 91 def only_if_cached? @only_if_cached end
Returns true if the only-if-cached directive is present. This directive indicates that the client only wishes to obtain a stored response. If a valid stored response is not available, the server should respond with a 504 (Gateway Timeout) status.
Private Instance Methods
Source
# File lib/action_dispatch/http/cache.rb, line 147 def parse_directives(header_value) return unless header_value header_value.delete(" ").downcase.split(",").each do |directive| name, value = directive.split("=", 2) case name when "max-age" @max_age = value.to_i when "min-fresh" @min_fresh = value.to_i when "stale-if-error" @stale_if_error = value.to_i when "no-cache" @no_cache = true when "no-store" @no_store = true when "no-transform" @no_transform = true when "only-if-cached" @only_if_cached = true when "max-stale" @max_stale = value ? value.to_i : true end end end