Class: Faulty::Cache::AutoWire

Inherits:
Object
  • Object
show all
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

Class Method Details

.wrap(cache, **options) {|Options| ... } ⇒ Object

Wrap a cache backend with sensible defaults

If the cache is nil, create a new Default.

If the backend is not fault tolerant, wrap it in CircuitProxy and FaultTolerantProxy.

Parameters:

  • cache (Interface)

    A cache backend

  • options (Hash)

    Attributes for Options

Yields:

  • (Options)

    For setting options in a block



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/faulty/cache/auto_wire.rb', line 40

def wrap(cache, **options, &block)
  options = Options.new(options, &block)
  if cache.nil?
    Cache::Default.new
  elsif cache.fault_tolerant?
    cache
  else
    Cache::FaultTolerantProxy.new(
      Cache::CircuitProxy.new(cache, circuit: options.circuit, notifier: options.notifier),
      notifier: options.notifier
    )
  end
end