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.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/zold/cached_wallets.rb', line 18 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 end |
Instance Method Details
#acq(id, exclusive: false) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/zold/cached_wallets.rb', line 31 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 |