Class: Moneta::Pool

Inherits:
Wrapper show all
Defined in:
lib/moneta/pool.rb

Overview

Creates a pool of stores. Each thread gets its own store.

Examples:

Add ‘Moneta::Pool` to proxy stack

Moneta.build do
  use(:Pool) do
    # Every thread gets its own instance
    adapter :MemcachedNative
  end
end

Instance Method Summary collapse

Methods inherited from Wrapper

#clear, #create, #delete, #features, #increment, #key?, #load, #store

Methods inherited from Proxy

#clear, #create, #delete, #features, #increment, #key?, #load, #store

Methods included from Defaults

#[], #[]=, #create, #decrement, #features, #fetch, included, #increment, #key?, #supports?

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options = {}, &block) ⇒ Pool

Returns a new instance of Pool.

Parameters:

  • adapter (Moneta store)

    The underlying store

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :mutex (String) — default: ::Mutex.new

    Mutex object



20
21
22
23
24
25
26
# File 'lib/moneta/pool.rb', line 20

def initialize(options = {}, &block)
  super(nil)
  @mutex = options[:mutex] || ::Mutex.new
  @id = "Moneta::Pool(#{object_id})"
  @builder = Builder.new(&block)
  @pool, @all = [], []
end

Instance Method Details

#closeObject



28
29
30
31
32
33
34
# File 'lib/moneta/pool.rb', line 28

def close
  @mutex.synchronize do
    raise '#close can only be called when no thread is using the pool' if @all.size != @pool.size
    @all.each(&:close)
    @all = @pool = nil
  end
end