module Stockpile::CachedValueReader
Stockpile::CachedValueReader
¶ ↑
Service class to wrap decision point of wether a value should be returned from cache or computed and stored in cache
Public Instance Methods
read_or_yield(db: :default, key:, ttl:, &block)
click to toggle source
# 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