Class: Protocol::HTTP::Header::CacheControl

Inherits:
Split
  • Object
show all
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

Split::COMMA

Instance Method Summary collapse

Methods inherited from Split

#to_s, trailer?

Constructor Details

#initialize(value = nil) ⇒ CacheControl

Initializes the cache control header with the given value. The value is expected to be a comma-separated string of cache directives.



50
51
52
# File 'lib/protocol/http/header/cache_control.rb', line 50

def initialize(value = nil)
  super(value&.downcase)
end

Instance Method Details

#<<(value) ⇒ Object

Adds a directive to the Cache-Control header. The value will be normalized to lowercase before being added.



57
58
59
# File 'lib/protocol/http/header/cache_control.rb', line 57

def << value
  super(value.downcase)
end

#dynamic?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/protocol/http/header/cache_control.rb', line 67

def dynamic?
  self.include?(DYNAMIC)
end

#max_ageObject



107
108
109
# File 'lib/protocol/http/header/cache_control.rb', line 107

def max_age
  find_integer_value(MAX_AGE)
end

#must_revalidate?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/protocol/http/header/cache_control.rb', line 97

def must_revalidate?
  self.include?(MUST_REVALIDATE)
end

#no_cache?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/protocol/http/header/cache_control.rb', line 87

def no_cache?
  self.include?(NO_CACHE)
end

#no_store?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/protocol/http/header/cache_control.rb', line 92

def no_store?
  self.include?(NO_STORE)
end

#private?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/protocol/http/header/cache_control.rb', line 77

def private?
  self.include?(PRIVATE)
end

#proxy_revalidate?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/protocol/http/header/cache_control.rb', line 102

def proxy_revalidate?
  self.include?(PROXY_REVALIDATE)
end

#public?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/protocol/http/header/cache_control.rb', line 82

def public?
  self.include?(PUBLIC)
end

#s_maxageObject



112
113
114
# File 'lib/protocol/http/header/cache_control.rb', line 112

def s_maxage
  find_integer_value(S_MAXAGE)
end

#static?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/protocol/http/header/cache_control.rb', line 62

def static?
  self.include?(STATIC)
end

#streaming?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/protocol/http/header/cache_control.rb', line 72

def streaming?
  self.include?(STREAMING)
end