class Droxy::MaxAgeCache

Constants

Entry

Attributes

duration[R]

Public Class Methods

new(duration: @duration, @store = duration, {}) click to toggle source
# File lib/droxy/max_age_cache.rb, line 7
def initialize duration:
  @duration, @store = duration, {}
end

Public Instance Methods

acceptable?(entry) click to toggle source
# File lib/droxy/max_age_cache.rb, line 18
def acceptable? entry
  return false if entry.nil? || entry.value.nil?
  Time.now - entry.created < duration
end
fetch(key, &block) click to toggle source
# File lib/droxy/max_age_cache.rb, line 11
def fetch key, &block
  unless acceptable? @store[key]
    @store[key] = Entry.new block.call, Time.now
  end
  @store[key].value
end