Class: HTTP::Cache::Headers

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/http/cache/headers.rb

Overview

Convenience methods around cache control headers.

Instance Method Summary collapse

Constructor Details

#initialize(headers) ⇒ Headers



10
11
12
13
14
15
16
# File 'lib/http/cache/headers.rb', line 10

def initialize(headers)
  if headers.is_a? HTTP::Headers
    super headers
  else
    super HTTP::Headers.coerce headers
  end
end

Instance Method Details

#forces_revalidation?Boolean



19
20
21
# File 'lib/http/cache/headers.rb', line 19

def forces_revalidation?
  must_revalidate? || max_age == 0
end

#max_ageNumeric

considered fresh.



50
51
52
# File 'lib/http/cache/headers.rb', line 50

def max_age
  explicit_max_age || seconds_til_expires || Float::INFINITY
end

#must_revalidate?Boolean



24
25
26
# File 'lib/http/cache/headers.rb', line 24

def must_revalidate?
  matches?(/\bmust-revalidate\b/i)
end

#no_cache?Boolean



29
30
31
# File 'lib/http/cache/headers.rb', line 29

def no_cache?
  matches?(/\bno-cache\b/i)
end

#no_store?Boolean



34
35
36
# File 'lib/http/cache/headers.rb', line 34

def no_store?
  matches?(/\bno-store\b/i)
end

#private?Boolean



44
45
46
# File 'lib/http/cache/headers.rb', line 44

def private?
  matches?(/\bprivate\b/i)
end

#public?Boolean



39
40
41
# File 'lib/http/cache/headers.rb', line 39

def public?
  matches?(/\bpublic\b/i)
end

#vary_star?Boolean



55
56
57
# File 'lib/http/cache/headers.rb', line 55

def vary_star?
  get("Vary").any? { |v| "*" == v.strip }
end