Class: Zache
- Inherits:
-
Object
- Object
- Zache
- Defined in:
- lib/zache.rb
Overview
Cache.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2018 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
- #get(key, lifetime: 60 * 60) ⇒ Object
-
#initialize(sync: true) ⇒ Zache
constructor
A new instance of Zache.
Constructor Details
#initialize(sync: true) ⇒ Zache
Returns a new instance of Zache.
30 31 32 33 34 |
# File 'lib/zache.rb', line 30 def initialize(sync: true) @hash = {} @sync = sync @mutex = Mutex.new end |
Instance Method Details
#get(key, lifetime: 60 * 60) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/zache.rb', line 36 def get(key, lifetime: 60 * 60) if @sync @mutex.synchronize do calc(key, lifetime) { yield } end else calc(key, lifetime) { yield } end end |