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.
309 310 311 312 313 |
# File 'lib/moneta/pool.rb', line 309 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
317 |
# File 'lib/moneta/pool.rb', line 317 def close; end |
#each_key(&block) ⇒ Object
319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/moneta/pool.rb', line 319 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
338 339 340 |
# File 'lib/moneta/pool.rb', line 338 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.
333 334 335 336 |
# File 'lib/moneta/pool.rb', line 333 def stop @manager.stop nil end |