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(db: :default, key:, ttl:, &block) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/stockpile/cached_value_reader.rb', line 25 def read_or_yield(db: :default, key:, ttl:, &block) if (result = Stockpile::Cache.get(db: db, key: key, compress: RedisConnections.compression?(db: db))) result else Stockpile::Executor.perform(db: db, key: key, ttl: ttl, &block) end end |