Class: HLS::Cache
- Inherits:
-
Object
- Object
- HLS::Cache
- Defined in:
- lib/hls/cache.rb
Overview
Wraps a Rails.cache-shaped backend with a TTL so the read-side Manifest can call ‘cache.fetch(key) { … }` without plumbing the TTL alongside the backend at every call site.
Profile classes attach an instance via ‘cache`:
class CourseVideo < ApplicationVideo
def self.cache = HLS::Cache.new(backend: Rails.cache, ttl: 5.minutes)
end
The Manifest also accepts any object responding to ‘fetch(key, &block)` directly — wrapping is just the convenience path for backends like Rails.cache that need a TTL hint.
Constant Summary collapse
- DEFAULT_TTL =
300
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#ttl ⇒ Object
readonly
Returns the value of attribute ttl.
Instance Method Summary collapse
- #fetch(key, &block) ⇒ Object
-
#initialize(backend:, ttl: DEFAULT_TTL) ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize(backend:, ttl: DEFAULT_TTL) ⇒ Cache
Returns a new instance of Cache.
22 23 24 25 |
# File 'lib/hls/cache.rb', line 22 def initialize(backend:, ttl: DEFAULT_TTL) @backend = backend @ttl = Integer(ttl) end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
20 21 22 |
# File 'lib/hls/cache.rb', line 20 def backend @backend end |
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
20 21 22 |
# File 'lib/hls/cache.rb', line 20 def ttl @ttl end |
Instance Method Details
#fetch(key, &block) ⇒ Object
27 28 29 |
# File 'lib/hls/cache.rb', line 27 def fetch(key, &block) backend.fetch(key, expires_in: ttl, &block) end |