Class: Async::Cache
- Inherits:
-
Object
- Object
- Async::Cache
- Defined in:
- lib/async/cache.rb
Defined Under Namespace
Classes: Item
Instance Method Summary collapse
Instance Method Details
#cache(id, duration:, parent: Async::Task.current) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/async/cache.rb', line 8 def cache(id, duration:, parent: Async::Task.current) cleanup! find_or_create(id, duration:) do |item| parent.async do |task| item.task = task item.value = yield(id) if block_given? item.created_at = Time.now end.wait end.value end |
#cleanup! ⇒ Object
19 |
# File 'lib/async/cache.rb', line 19 def cleanup! = storage.delete_if { _2.expired? } |
#count ⇒ Object
20 |
# File 'lib/async/cache.rb', line 20 def count = storage.count |