Class: Faulty::Cache::FaultTolerantProxy
- Inherits:
-
Object
- Object
- Faulty::Cache::FaultTolerantProxy
- Defined in:
- lib/faulty/cache/fault_tolerant_proxy.rb
Overview
A wrapper for cache backends that may raise errors
Scope automatically wraps all non-fault-tolerant cache backends with this class.
If the cache backend raises a StandardError, it will be captured and
sent to the notifier.
Defined Under Namespace
Classes: Options
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#fault_tolerant? ⇒ true
This cache makes any cache fault tolerant, so this is always
true. -
#initialize(cache, **options) {|Options| ... } ⇒ FaultTolerantProxy
constructor
A new instance of FaultTolerantProxy.
-
#read(key) ⇒ Object?
Read from the cache safely.
-
#write(key, value, expires_in: nil) ⇒ void
Write to the cache safely.
Constructor Details
#initialize(cache, **options) {|Options| ... } ⇒ FaultTolerantProxy
Returns a new instance of FaultTolerantProxy.
34 35 36 37 |
# File 'lib/faulty/cache/fault_tolerant_proxy.rb', line 34 def initialize(cache, **, &block) @cache = cache @options = Options.new(, &block) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/faulty/cache/fault_tolerant_proxy.rb', line 13 def @options end |
Instance Method Details
#fault_tolerant? ⇒ true
This cache makes any cache fault tolerant, so this is always true
69 70 71 |
# File 'lib/faulty/cache/fault_tolerant_proxy.rb', line 69 def fault_tolerant? true end |
#read(key) ⇒ Object?
Read from the cache safely
If the backend raises a StandardError, this will return nil.
46 47 48 49 50 51 |
# File 'lib/faulty/cache/fault_tolerant_proxy.rb', line 46 def read(key) @cache.read(key) rescue StandardError => e .notifier.notify(:cache_failure, key: key, action: :read, error: e) nil end |
#write(key, value, expires_in: nil) ⇒ void
This method returns an undefined value.
Write to the cache safely
If the backend raises a StandardError, the write will be ignored
59 60 61 62 63 64 |
# File 'lib/faulty/cache/fault_tolerant_proxy.rb', line 59 def write(key, value, expires_in: nil) @cache.write(key, value, expires_in: expires_in) rescue StandardError .notifier.notify(:cache_failure, key: key, action: :write, error: e) nil end |