Sha256: fb1388c05973085c13b53c58738c49a2a32b3a2f0092cb9523ec9bfb4312772b
Contents?: true
Size: 819 Bytes
Versions: 29
Compression:
Stored size: 819 Bytes
Contents
class ProconBypassMan::OnMemoryCache class CacheValue # @param [Time] attr_accessor :expired_at attr_accessor :value def initialize(expired_at: , value: ) self.expired_at = expired_at self.value = value end end def initialize @table = {} end # @param [Integer] expires_in 秒数 # @param [String] key def fetch(key: , expires_in: , &block) now = Time.now if @table[key].nil? value = block.call value_object = CacheValue.new(expired_at: now + expires_in, value: value) @table[key] = value_object return value end if @table[key].expired_at < now value = block.call @table[key] = CacheValue.new(expired_at: now + expires_in, value: value) return value else return @table[key].value end end end
Version data entries
29 entries across 29 versions & 1 rubygems