Class: Zold::CachedWallets
- Inherits:
-
Object
- Object
- Zold::CachedWallets
- Defined in:
- lib/zold/cached_wallets.rb
Overview
Collection of local wallets
Instance Method Summary collapse
- #acq(id, exclusive: false) ⇒ Object
- #all ⇒ Object
-
#initialize(wallets) ⇒ CachedWallets
constructor
A new instance of CachedWallets.
- #path ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(wallets) ⇒ CachedWallets
Returns a new instance of CachedWallets.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/zold/cached_wallets.rb', line 33 def initialize(wallets) @wallets = wallets @zache = Zache.new @clean = Thread.start do Endless.new('cached_wallets').run do sleep 60 @zache.clean end end end |
Instance Method Details
#acq(id, exclusive: false) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/zold/cached_wallets.rb', line 56 def acq(id, exclusive: false) @wallets.acq(id, exclusive: exclusive) do |wallet| c = @zache.get(id.to_s, lifetime: 5 * 60) { wallet } res = yield c c.flush if exclusive res end end |
#all ⇒ Object
52 53 54 |
# File 'lib/zold/cached_wallets.rb', line 52 def all @wallets.all end |
#path ⇒ Object
48 49 50 |
# File 'lib/zold/cached_wallets.rb', line 48 def path @wallets.path end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/zold/cached_wallets.rb', line 44 def to_s @wallets.to_s end |