Class: Moneta::Pool
Overview
Creates a thread-safe pool. Stores are in the pool are transparently checked in and out in order to perform operations.
A ‘max` setting can be specified in order to limit the pool size. If `max` stores are all checked out at once, the next check-out will block until one of the other stores are checked in.
A ‘ttl` setting can be specified, giving the number of seconds to wait without any activity before shrinking the pool size back down to the min size.
A ‘timeout` setting can be specified, giving the number of seconds to wait when checking out a store, before an error is raised. When the pool has a `:max` size, a timeout is highly advisable.
Defined Under Namespace
Classes: PoolManager, Reply, ShutdownError, TimeoutError
Instance Method Summary collapse
-
#close ⇒ Object
Closing has no effect on the pool, as stores are closed in the background by the manager after the ttl.
- #each_key(&block) ⇒ Object
-
#initialize(options = {}) { ... } ⇒ Pool
constructor
A new instance of Pool.
- #stats ⇒ Object
-
#stop ⇒ Object
Tells the manager to close all stores.
Methods inherited from Wrapper
#clear, #config, #create, #delete, #features, #fetch_values, #increment, #key?, #load, #merge!, #slice, #store, #values_at
Methods inherited from Proxy
#clear, #config, #create, #delete, #features, features_mask, #fetch_values, #increment, #key?, #load, #merge!, not_supports, #slice, #store, #values_at
Methods included from Config
Methods included from Defaults
#[], #[]=, #create, #decrement, #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 = {}) { ... } ⇒ Pool
Returns a new instance of Pool.
311 312 313 314 315 |
# File 'lib/moneta/pool.rb', line 311 def initialize( = {}, &block) @id = "Moneta::Pool(#{object_id})" @manager = PoolManager.new(Builder.new(&block), **) super(nil, ) end |
Instance Method Details
#close ⇒ Object
Closing has no effect on the pool, as stores are closed in the background by the manager after the ttl
319 |
# File 'lib/moneta/pool.rb', line 319 def close; end |
#each_key(&block) ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/moneta/pool.rb', line 321 def each_key(&block) wrap(:each_key) do raise NotImplementedError, "each_key is not supported on this proxy" \ unless supports? :each_key return enum_for(:each_key) { adapter ? adapter.each_key.size : check_out! { adapter.each_key.size } } unless block_given? adapter.each_key(&block) self end end |
#stats ⇒ Object
340 341 342 |
# File 'lib/moneta/pool.rb', line 340 def stats @manager.stats end |
#stop ⇒ Object
Tells the manager to close all stores. It will not be possible to use the store after this.
335 336 337 338 |
# File 'lib/moneta/pool.rb', line 335 def stop @manager.stop nil end |