class Logster::Cache
Public Class Methods
new(age = 2)
click to toggle source
# File lib/logster/cache.rb, line 5 def initialize(age = 2) @age = age @hash = {} end
Public Instance Methods
clear(key)
click to toggle source
# File lib/logster/cache.rb, line 17 def clear(key) @hash.delete(key) end
fetch(key) { || ... }
click to toggle source
# File lib/logster/cache.rb, line 10 def fetch(key) if !@hash.key?(key) || @hash[key][:created_at] + @age < Process.clock_gettime(Process::CLOCK_MONOTONIC) @hash[key] = { data: yield, created_at: Process.clock_gettime(Process::CLOCK_MONOTONIC) } end @hash[key][:data] end