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

Methods

Attributes

[R] max_age

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.

[R] max_stale

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.

[R] min_fresh

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.

[R] stale_if_error

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.

Class Public methods

new(cache_control_header)

📝 Source code
# 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
🔎 See on GitHub

Instance Public methods

max_stale?()

Returns true if max-stale directive is present (with or without a value)

📝 Source code
# File actionpack/lib/action_dispatch/http/cache.rb, line 127
          def max_stale?
            !@max_stale.nil?
          end
🔎 See on GitHub

max_stale_unlimited?()

Returns true if max-stale directive is present without a value (unlimited staleness)

📝 Source code
# File actionpack/lib/action_dispatch/http/cache.rb, line 132
          def max_stale_unlimited?
            @max_stale == true
          end
🔎 See on GitHub

no_cache?()

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 code
# File actionpack/lib/action_dispatch/http/cache.rb, line 98
          def no_cache?
            @no_cache
          end
🔎 See on GitHub

no_store?()

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 code
# File actionpack/lib/action_dispatch/http/cache.rb, line 105
          def no_store?
            @no_store
          end
🔎 See on GitHub

no_transform?()

Returns true if the no-transform directive is present. This directive indicates that a cache or proxy must not transform the payload.

📝 Source code
# File actionpack/lib/action_dispatch/http/cache.rb, line 111
          def no_transform?
            @no_transform
          end
🔎 See on GitHub

only_if_cached?()

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.

📝 Source code
# File actionpack/lib/action_dispatch/http/cache.rb, line 91
          def only_if_cached?
            @only_if_cached
          end
🔎 See on GitHub