Sha256: 82ce8746337ce57fd2a969aedf36fb2b288e917b851a4c174a4ee79e7757835e
Contents?: true
Size: 462 Bytes
Versions: 27
Compression:
Stored size: 462 Bytes
Contents
# frozen_string_literal: true module Logster class Cache def initialize(age = 2) @age = age @hash = {} end 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 def clear(key) @hash.delete(key) end end end
Version data entries
27 entries across 27 versions & 1 rubygems