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

Returns a new instance of 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

Returns does this message force revalidation.

Returns:

  • (Boolean)

    does this message force revalidation



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

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

#max_ageNumeric

considered fresh.

Returns:

  • (Numeric)

    the max number of seconds this message is



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

Returns does the cache control include 'must-revalidate'.

Returns:

  • (Boolean)

    does the cache control include 'must-revalidate'



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

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

#no_cache?Boolean

Returns does the cache control include 'no-cache'.

Returns:

  • (Boolean)

    does the cache control include 'no-cache'



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

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

#no_store?Boolean

Returns does the cache control include 'no-stor'.

Returns:

  • (Boolean)

    does the cache control include 'no-stor'



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

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

#private?Boolean

Returns does the cache control include 'private'.

Returns:

  • (Boolean)

    does the cache control include 'private'



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

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

#public?Boolean

Returns does the cache control include 'public'.

Returns:

  • (Boolean)

    does the cache control include 'public'



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

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

#vary_star?Boolean

Returns is the vary header set to '*'.

Returns:

  • (Boolean)

    is the vary header set to '*'



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

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