class Arturo::FeatureCaching::Cache

Quack like a Rails cache.

Public Class Methods

new() click to toggle source
# File lib/arturo/feature_caching.rb, line 198
def initialize
  @data = {} # of the form {key => [value, expires_at or nil]}
end

Public Instance Methods

clear() click to toggle source
# File lib/arturo/feature_caching.rb, line 226
def clear
  @data.clear
end
delete(name) click to toggle source
# File lib/arturo/feature_caching.rb, line 211
def delete(name)
  @data.delete(name)
end
read(name, options = nil) click to toggle source
# File lib/arturo/feature_caching.rb, line 202
def read(name, options = nil)
  value, expires_at = *@data[name]
  if value && (expires_at.blank? || expires_at > Time.now)
    value
  else
    nil
  end
end
write(name, value, options = nil) click to toggle source
# File lib/arturo/feature_caching.rb, line 215
def write(name, value, options = nil)
  expires_at = if options && options.respond_to?(:[]) && options[:expires_in]
    Time.now + options.delete(:expires_in)
  else
    nil
  end
  value.freeze.tap do |val|
    @data[name] = [value, expires_at]
  end
end