class Grenache::Cache

Public Class Methods

new(expiring=5) click to toggle source
# File lib/grenache/cache.rb, line 4
def initialize expiring=5
  @cache = {}
  @expiring = expiring
end

Public Instance Methods

has?(key) click to toggle source
# File lib/grenache/cache.rb, line 9
def has?(key)
  if @cache.keys.include?(key) && @cache[key][:expire] >= Time.now
    return @cache[key][:val]
  end
end
save(key, val) click to toggle source
# File lib/grenache/cache.rb, line 15
def save(key, val)
  @cache[key] = { val: val, expire: Time.now+@expiring }
  val
end