Sha256: f176444db850848b5489b617a526dfdda25a84c9935d787a490cf6f719db86bb
Contents?: true
Size: 484 Bytes
Versions: 8
Compression:
Stored size: 484 Bytes
Contents
module Logster class Cache def initialize(age = 2) @age = age @hash = { created_at: Process.clock_gettime(Process::CLOCK_MONOTONIC) } end def fetch if !@hash.key?(:data) || @hash[:created_at] + @age < Process.clock_gettime(Process::CLOCK_MONOTONIC) @hash[:data] = yield @hash[:created_at] = Process.clock_gettime(Process::CLOCK_MONOTONIC) end @hash[:data] end def clear @hash.delete(:data) end end end
Version data entries
8 entries across 8 versions & 1 rubygems