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, #each_key, #features, #fetch_values, #increment, #key?, #load, #merge!, #slice, #store, #values_at

Methods inherited from Proxy

#clear, #create, #delete, #each_key, #features, features_mask, #fetch_values, #increment, #key?, #load, #merge!, not_supports, #slice, #store, #values_at

Methods included from Defaults

#[], #[]=, #create, #decrement, #each_key, #features, #fetch, #fetch_values, included, #increment, #key?, #merge!, #slice, #supports?, #update, #values_at

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

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

Returns a new instance of Pool

Parameters:

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

Options Hash (options):

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

    Mutex object


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

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


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

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