Class: Faulty::Cache::Default
- Inherits:
- 
      Object
      
        - Object
- Faulty::Cache::Default
 
- Extended by:
- Forwardable
- Defined in:
- lib/faulty/cache/default.rb
Overview
The default cache implementation
It tries to make a logical decision of what cache implementation to use based on the current environment.
- If Rails is loaded, it will use Rails.cache
- If ActiveSupport is available, it will use an ActiveSupport::Cache::MemoryStore
- Otherwise it will use a Null
Instance Method Summary collapse
- 
  
    
      #fault_tolerant  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Can this cache backend raise an error?. 
- 
  
    
      #initialize  ⇒ Default 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Default. 
- 
  
    
      #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 ⇒ Default
Returns a new instance of Default.
| 16 17 18 19 20 21 22 23 24 | # File 'lib/faulty/cache/default.rb', line 16 def initialize @cache = if defined?(::Rails) Cache::Rails.new(::Rails.cache) elsif defined?(::ActiveSupport::Cache::MemoryStore) Cache::Rails.new(ActiveSupport::Cache::MemoryStore.new, fault_tolerant: true) else Cache::Null.new end end | 
Instance Method Details
#fault_tolerant ⇒ Boolean
Can this cache backend raise an error?
If the cache backend returns false from this method, it will be wrapped in a FaultTolerantProxy, otherwise it will be used as-is.
| 34 | # File 'lib/faulty/cache/default.rb', line 34 def_delegators :@cache, :read, :write, :fault_tolerant? | 
#read(key) ⇒ Object?
Retrieve a value from the cache if available
| 34 | # File 'lib/faulty/cache/default.rb', line 34 def_delegators :@cache, :read, :write, :fault_tolerant? | 
#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.
| 34 | # File 'lib/faulty/cache/default.rb', line 34 def_delegators :@cache, :read, :write, :fault_tolerant? |