Class: Faulty::Cache::Rails
- Inherits:
-
Object
- Object
- Faulty::Cache::Rails
- Defined in:
- lib/faulty/cache/rails.rb
Overview
A wrapper for a Rails or ActiveSupport cache
Instance Method Summary collapse
-
#fault_tolerant? ⇒ Boolean
Although ActiveSupport cache implementations are fault-tolerant, Rails.cache is not guranteed to be fault tolerant.
-
#initialize(cache = ::Rails.cache, fault_tolerant: false) ⇒ Rails
constructor
A new instance of Rails.
-
#read(key) ⇒ Object?
Retrieve a value from the cache if available.
-
#write(key, value, expires_in: nil) ⇒ Object?
Retrieve a value from the cache if available.
Constructor Details
#initialize(cache = ::Rails.cache, fault_tolerant: false) ⇒ Rails
Returns a new instance of Rails.
11 12 13 14 |
# File 'lib/faulty/cache/rails.rb', line 11 def initialize(cache = ::Rails.cache, fault_tolerant: false) @cache = cache @fault_tolerant = fault_tolerant end |
Instance Method Details
#fault_tolerant? ⇒ Boolean
Although ActiveSupport cache implementations are fault-tolerant, Rails.cache is not guranteed to be fault tolerant. For this reason, we require the user of this class to explicitly mark this cache as fault-tolerant using the #initialize parameter.
32 33 34 |
# File 'lib/faulty/cache/rails.rb', line 32 def fault_tolerant? @fault_tolerant end |
#read(key) ⇒ Object?
Retrieve a value from the cache if available
17 18 19 |
# File 'lib/faulty/cache/rails.rb', line 17 def read(key) @cache.read(key) end |
#write(key, value, expires_in: nil) ⇒ Object?
Retrieve a value from the cache if available
22 23 24 |
# File 'lib/faulty/cache/rails.rb', line 22 def write(key, value, expires_in: nil) @cache.write(key, value, expires_in: expires_in) end |