Class: ActionDispatch::Http::Cache::Request::CacheControlDirectives
- Inherits:
-
Object
- Object
- ActionDispatch::Http::Cache::Request::CacheControlDirectives
- Defined in:
- lib/action_dispatch/http/cache.rb
Overview
Represents the HTTP Cache-Control header for requests, providing methods to access various cache control directives Reference: https://www.rfc-editor.org/rfc/rfc9111.html#name-request-directives
Instance Attribute Summary collapse
-
#max_age ⇒ Object
readonly
Returns the value of the max-age directive.
-
#max_stale ⇒ Object
readonly
Returns the value of the max-stale directive.
-
#min_fresh ⇒ Object
readonly
Returns the value of the min-fresh directive.
-
#stale_if_error ⇒ Object
readonly
Returns the value of the stale-if-error directive.
Instance Method Summary collapse
-
#initialize(cache_control_header) ⇒ CacheControlDirectives
constructor
A new instance of CacheControlDirectives.
-
#max_stale? ⇒ Boolean
Returns true if max-stale directive is present (with or without a value).
-
#max_stale_unlimited? ⇒ Boolean
Returns true if max-stale directive is present without a value (unlimited staleness).
-
#no_cache? ⇒ Boolean
Returns true if the no-cache directive is present.
-
#no_store? ⇒ Boolean
Returns true if the no-store directive is present.
-
#no_transform? ⇒ Boolean
Returns true if the no-transform directive is present.
-
#only_if_cached? ⇒ Boolean
Returns true if the only-if-cached directive is present.
Constructor Details
#initialize(cache_control_header) ⇒ CacheControlDirectives
Returns a new instance of CacheControlDirectives.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/action_dispatch/http/cache.rb', line 79 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 |
Instance Attribute Details
#max_age ⇒ Object (readonly)
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.
122 123 124 |
# File 'lib/action_dispatch/http/cache.rb', line 122 def max_age @max_age end |
#max_stale ⇒ Object (readonly)
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.
128 129 130 |
# File 'lib/action_dispatch/http/cache.rb', line 128 def max_stale @max_stale end |
#min_fresh ⇒ Object (readonly)
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.
143 144 145 |
# File 'lib/action_dispatch/http/cache.rb', line 143 def min_fresh @min_fresh end |
#stale_if_error ⇒ Object (readonly)
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.
148 149 150 |
# File 'lib/action_dispatch/http/cache.rb', line 148 def stale_if_error @stale_if_error end |
Instance Method Details
#max_stale? ⇒ Boolean
Returns true if max-stale directive is present (with or without a value)
131 132 133 |
# File 'lib/action_dispatch/http/cache.rb', line 131 def max_stale? !@max_stale.nil? end |
#max_stale_unlimited? ⇒ Boolean
Returns true if max-stale directive is present without a value (unlimited staleness)
136 137 138 |
# File 'lib/action_dispatch/http/cache.rb', line 136 def max_stale_unlimited? @max_stale == true end |
#no_cache? ⇒ Boolean
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.
102 103 104 |
# File 'lib/action_dispatch/http/cache.rb', line 102 def no_cache? @no_cache end |
#no_store? ⇒ Boolean
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.
109 110 111 |
# File 'lib/action_dispatch/http/cache.rb', line 109 def no_store? @no_store end |
#no_transform? ⇒ Boolean
Returns true if the no-transform directive is present. This directive indicates that a cache or proxy must not transform the payload.
115 116 117 |
# File 'lib/action_dispatch/http/cache.rb', line 115 def no_transform? @no_transform end |
#only_if_cached? ⇒ Boolean
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.
95 96 97 |
# File 'lib/action_dispatch/http/cache.rb', line 95 def only_if_cached? @only_if_cached end |