Class: Protocol::HTTP::Header::CacheControl
- Defined in:
- lib/protocol/http/header/cache_control.rb
Overview
Represents the ‘cache-control` header, which is a list of cache directives.
Constant Summary collapse
- PRIVATE =
The ‘private` directive indicates that the response is intended for a single user and must not be stored by shared caches.
"private"- PUBLIC =
The ‘public` directive indicates that the response may be stored by any cache, even if it would normally be considered non-cacheable.
"public"- NO_CACHE =
The ‘no-cache` directive indicates that caches must revalidate the response with the origin server before serving it to clients.
"no-cache"- NO_STORE =
The ‘no-store` directive indicates that caches must not store the response under any circumstances.
"no-store"- MAX_AGE =
The ‘max-age` directive indicates the maximum amount of time, in seconds, that a response is considered fresh.
"max-age"- S_MAXAGE =
The ‘s-maxage` directive is similar to `max-age` but applies only to shared caches. If both `s-maxage` and `max-age` are present, `s-maxage` takes precedence in shared caches.
"s-maxage"- STATIC =
The ‘static` directive is a custom directive often used to indicate that the resource is immutable or rarely changes, allowing longer caching periods.
"static"- DYNAMIC =
The ‘dynamic` directive is a custom directive used to indicate that the resource is generated dynamically and may change frequently, requiring shorter caching periods.
"dynamic"- STREAMING =
The ‘streaming` directive is a custom directive used to indicate that the resource is intended for progressive or chunked delivery, such as live video streams.
"streaming"- MUST_REVALIDATE =
The ‘must-revalidate` directive indicates that once a response becomes stale, caches must not use it to satisfy subsequent requests without revalidating it with the origin server.
"must-revalidate"- PROXY_REVALIDATE =
The ‘proxy-revalidate` directive is similar to `must-revalidate` but applies only to shared caches.
"proxy-revalidate"
Constants inherited from Split
Class Method Summary collapse
-
.coerce(value) ⇒ Object
Coerces a value into a parsed header object.
-
.parse(value) ⇒ Object
Parses a raw header value.
Instance Method Summary collapse
-
#<<(value) ⇒ Object
Adds a directive to the ‘cache-control` header.
- #dynamic? ⇒ Boolean
- #max_age ⇒ Object
- #must_revalidate? ⇒ Boolean
- #no_cache? ⇒ Boolean
- #no_store? ⇒ Boolean
- #private? ⇒ Boolean
- #proxy_revalidate? ⇒ Boolean
- #public? ⇒ Boolean
- #s_maxage ⇒ Object
- #static? ⇒ Boolean
- #streaming? ⇒ Boolean
Methods inherited from Split
Constructor Details
This class inherits a constructor from Protocol::HTTP::Header::Split
Class Method Details
.coerce(value) ⇒ Object
Coerces a value into a parsed header object.
59 60 61 62 63 64 65 66 |
# File 'lib/protocol/http/header/cache_control.rb', line 59 def self.coerce(value) case value when Array self.new(value.map(&:downcase)) else self.parse(value.to_s) end end |
.parse(value) ⇒ Object
Parses a raw header value.
51 52 53 |
# File 'lib/protocol/http/header/cache_control.rb', line 51 def self.parse(value) self.new(value.downcase.split(COMMA)) end |
Instance Method Details
#<<(value) ⇒ Object
Adds a directive to the ‘cache-control` header. The value will be normalized to lowercase before being added.
71 72 73 |
# File 'lib/protocol/http/header/cache_control.rb', line 71 def << value super(value.downcase) end |
#dynamic? ⇒ Boolean
81 82 83 |
# File 'lib/protocol/http/header/cache_control.rb', line 81 def dynamic? self.include?(DYNAMIC) end |
#max_age ⇒ Object
121 122 123 |
# File 'lib/protocol/http/header/cache_control.rb', line 121 def max_age find_integer_value(MAX_AGE) end |
#must_revalidate? ⇒ Boolean
111 112 113 |
# File 'lib/protocol/http/header/cache_control.rb', line 111 def must_revalidate? self.include?(MUST_REVALIDATE) end |
#no_cache? ⇒ Boolean
101 102 103 |
# File 'lib/protocol/http/header/cache_control.rb', line 101 def no_cache? self.include?(NO_CACHE) end |
#no_store? ⇒ Boolean
106 107 108 |
# File 'lib/protocol/http/header/cache_control.rb', line 106 def no_store? self.include?(NO_STORE) end |
#private? ⇒ Boolean
91 92 93 |
# File 'lib/protocol/http/header/cache_control.rb', line 91 def private? self.include?(PRIVATE) end |
#proxy_revalidate? ⇒ Boolean
116 117 118 |
# File 'lib/protocol/http/header/cache_control.rb', line 116 def proxy_revalidate? self.include?(PROXY_REVALIDATE) end |
#public? ⇒ Boolean
96 97 98 |
# File 'lib/protocol/http/header/cache_control.rb', line 96 def public? self.include?(PUBLIC) end |
#s_maxage ⇒ Object
126 127 128 |
# File 'lib/protocol/http/header/cache_control.rb', line 126 def s_maxage find_integer_value(S_MAXAGE) end |
#static? ⇒ Boolean
76 77 78 |
# File 'lib/protocol/http/header/cache_control.rb', line 76 def static? self.include?(STATIC) end |
#streaming? ⇒ Boolean
86 87 88 |
# File 'lib/protocol/http/header/cache_control.rb', line 86 def streaming? self.include?(STREAMING) end |