class FaradayCdnMetrics::ServerCaches::Fastly

Attributes

response_headers[R]

Public Class Methods

new(response_headers = {}) click to toggle source
# File lib/faraday_cdn_metrics/server_caches/fastly.rb, line 6
def initialize(response_headers = {})
  @response_headers = response_headers
end

Public Instance Methods

hit?() click to toggle source
# File lib/faraday_cdn_metrics/server_caches/fastly.rb, line 10
def hit?
  x_cache_hit?
end
hit_while_revalidate?() click to toggle source
# File lib/faraday_cdn_metrics/server_caches/fastly.rb, line 22
def hit_while_revalidate?
  max_age = fetch_max_age.to_i
  age = fetch_age.to_i

  x_cache_hit? && max_age > 0 && age > max_age
end
miss?() click to toggle source
# File lib/faraday_cdn_metrics/server_caches/fastly.rb, line 14
def miss?
  x_cache_miss?
end
pass?() click to toggle source
# File lib/faraday_cdn_metrics/server_caches/fastly.rb, line 18
def pass?
  x_cache_miss? && fetch_age.nil?
end

Private Instance Methods

fetch_age() click to toggle source
# File lib/faraday_cdn_metrics/server_caches/fastly.rb, line 45
def fetch_age
  response_headers.fetch('Age', nil)
end
fetch_max_age() click to toggle source
# File lib/faraday_cdn_metrics/server_caches/fastly.rb, line 41
def fetch_max_age
  response_headers.fetch('Cache-Control', '').match(/max-age=(\d+)/)&.captures&.first
end
x_cache_hit?() click to toggle source
# File lib/faraday_cdn_metrics/server_caches/fastly.rb, line 33
def x_cache_hit?
  response_headers.fetch('X-Cache', nil) == 'HIT'
end
x_cache_miss?() click to toggle source
# File lib/faraday_cdn_metrics/server_caches/fastly.rb, line 37
def x_cache_miss?
  response_headers.fetch('X-Cache', nil) == 'MISS'
end