Class: Faulty::Cache::AutoWire
- Inherits:
-
Object
- Object
- Faulty::Cache::AutoWire
- Defined in:
- lib/faulty/cache/auto_wire.rb
Overview
Automatically configure a cache backend
Used by Faulty#initialize to setup sensible cache defaults
Defined Under Namespace
Classes: Options
Class Method Summary collapse
-
.wrap(cache, **options) {|Options| ... } ⇒ Object
Wrap a cache backend with sensible defaults.
Class Method Details
.wrap(cache, **options) {|Options| ... } ⇒ Object
Wrap a cache backend with sensible defaults
If the cache is nil, create a new Default. Since Default may
resolve to a non-fault-tolerant backend (e.g. Rails.cache), the
result is passed back through wrap so it still receives the
CircuitProxy and FaultTolerantProxy wrappers when needed.
If the backend is not fault tolerant, wrap it in CircuitProxy and FaultTolerantProxy.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/faulty/cache/auto_wire.rb', line 43 def wrap(cache, **, &) = Options.new(, &) if cache.nil? wrap(Cache::Default.new, **.to_h) elsif cache.fault_tolerant? cache else Cache::FaultTolerantProxy.new( Cache::CircuitProxy.new(cache, circuit: .circuit, notifier: .notifier), notifier: .notifier ) end end |