Class: Lutaml::Store::HttpCacheEntry

Inherits:
Object
  • Object
show all
Includes:
Model::Serialize
Defined in:
lib/lutaml/store/http_cache_entry.rb

Instance Method Summary collapse

Instance Method Details

#ageObject



57
58
59
# File 'lib/lutaml/store/http_cache_entry.rb', line 57

def age
  Time.now - cached_at
end

#cacheable?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
# File 'lib/lutaml/store/http_cache_entry.rb', line 49

def cacheable?
  return false if status_code < 200 || status_code >= 400
  return false if cache_control["no-store"]
  return false if cache_control["private"]

  true
end

#expired?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
# File 'lib/lutaml/store/http_cache_entry.rb', line 34

def expired?
  return true if expires_at && Time.now > expires_at
  return true if max_age && (Time.now - cached_at) > max_age

  false
end

#fresh?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/lutaml/store/http_cache_entry.rb', line 27

def fresh?
  return false if expired?
  return false if must_revalidate?

  true
end

#must_revalidate?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/lutaml/store/http_cache_entry.rb', line 41

def must_revalidate?
  !!(cache_control["must-revalidate"] || cache_control["no-cache"])
end

#remaining_ttlObject



61
62
63
64
65
66
# File 'lib/lutaml/store/http_cache_entry.rb', line 61

def remaining_ttl
  return 0 if expired?
  return Float::INFINITY unless expires_at

  expires_at - Time.now
end

#stale?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/lutaml/store/http_cache_entry.rb', line 45

def stale?
  !fresh?
end