Class: Faulty::Cache::Rails
- Inherits:
-
Object
- Object
- Faulty::Cache::Rails
- Extended by:
- Forwardable
- 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: expires_in) ⇒ void
Write a value to the cache.
Constructor Details
#initialize(cache = ::Rails.cache, fault_tolerant: false) ⇒ Rails
Returns a new instance of Rails.
13 14 15 16 |
# File 'lib/faulty/cache/rails.rb', line 13 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.
31 32 33 |
# File 'lib/faulty/cache/rails.rb', line 31 def fault_tolerant? @fault_tolerant end |
#read(key) ⇒ Object?
Retrieve a value from the cache if available
23 |
# File 'lib/faulty/cache/rails.rb', line 23 def_delegators :@cache, :read, :write |
#write(key, value, expires_in: expires_in) ⇒ void
This method returns an undefined value.
Write a value to the cache
This may be any object. It's up to the cache implementation to serialize if necessary or raise an error if unsupported.
23 |
# File 'lib/faulty/cache/rails.rb', line 23 def_delegators :@cache, :read, :write |