Class: Zold::CachedWallets
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Zold::CachedWallets
- Defined in:
- lib/zold/cached_wallets.rb
Overview
Collection of local wallets
Instance Method Summary collapse
- #acq(id, exclusive: false) ⇒ Object
-
#initialize(wallets) ⇒ CachedWallets
constructor
A new instance of CachedWallets.
Constructor Details
#initialize(wallets) ⇒ CachedWallets
Returns a new instance of CachedWallets.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/zold/cached_wallets.rb', line 35 def initialize(wallets) @wallets = wallets @zache = Zache.new @clean = ThreadPool.new('cached-wallets') @clean.add do Endless.new('cached_wallets').run do sleep 5 @zache.clean end end super(wallets) end |
Instance Method Details
#acq(id, exclusive: false) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/zold/cached_wallets.rb', line 48 def acq(id, exclusive: false) @wallets.acq(id, exclusive: exclusive) do |wallet| c = @zache.get(id.to_s, lifetime: 15) { wallet } res = yield c c.flush if exclusive res end end |