Module: Stockpile::CachedValueReader
- Defined in:
- lib/stockpile/cached_value_reader.rb
Overview
Stockpile::CachedValueReader
Service class to wrap decision point of wether a value should be returned from cache or computed and stored in cache
Class Method Summary collapse
Class Method Details
.read_or_yield(key:, ttl:, &block) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/stockpile/cached_value_reader.rb', line 25 def read_or_yield(key:, ttl:, &block) if (result = Stockpile::Cache.get(key: key)) result else Stockpile::Executor.perform(key: key, ttl: ttl, &block) end end |