class Cache

Public Class Methods

new(source, fetchm, exp=86400) click to toggle source
# File lib/cache.rb, line 3
def initialize(source, fetchm, exp=86400)
  @expiry = exp
  @timestamp = 0
  @contents = []
  @source = source
  @fetch = fetchm
end

Public Instance Methods

contents() click to toggle source
# File lib/cache.rb, line 11
def contents
  if expired?
    put(@source.send(@fetch))
  end
  @contents
end
expired?() click to toggle source
# File lib/cache.rb, line 23
def expired?
  (Time.now.utc.to_i - @timestamp) > @expiry
end
put(stuff) click to toggle source
# File lib/cache.rb, line 18
def put(stuff)
  @timestamp = Time.now.utc.to_i
  @contents = stuff
end