Class: ActionDispatch::Http::Cache::Request::CacheControlDirectives

Inherits:
Object
  • Object
show all
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: www.rfc-editor.org/rfc/rfc9111.html#name-request-directives

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache_control_header) ⇒ CacheControlDirectives

Returns a new instance of CacheControlDirectives.



75
76
77
78
79
80
81
82
83
84
85
# 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

Instance Attribute Details

#max_ageObject (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.



118
119
120
# File 'lib/action_dispatch/http/cache.rb', line 118

def max_age
  @max_age
end

#max_staleObject (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.



124
125
126
# File 'lib/action_dispatch/http/cache.rb', line 124

def max_stale
  @max_stale
end

#min_freshObject (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.



139
140
141
# File 'lib/action_dispatch/http/cache.rb', line 139

def min_fresh
  @min_fresh
end

#stale_if_errorObject (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.



144
145
146
# File 'lib/action_dispatch/http/cache.rb', line 144

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)

Returns:

  • (Boolean)


127
128
129
# File 'lib/action_dispatch/http/cache.rb', line 127

def max_stale?
  !@max_stale.nil?
end

#max_stale_unlimited?Boolean

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

Returns:

  • (Boolean)


132
133
134
# File 'lib/action_dispatch/http/cache.rb', line 132

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.

Returns:

  • (Boolean)


98
99
100
# File 'lib/action_dispatch/http/cache.rb', line 98

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.

Returns:

  • (Boolean)


105
106
107
# File 'lib/action_dispatch/http/cache.rb', line 105

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.

Returns:

  • (Boolean)


111
112
113
# File 'lib/action_dispatch/http/cache.rb', line 111

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.

Returns:

  • (Boolean)


91
92
93
# File 'lib/action_dispatch/http/cache.rb', line 91

def only_if_cached?
  @only_if_cached
end