class HTTParty::Icebox::Cache
Cache
container¶ ↑
Pass a store name ('memory', etc) to initializer
Attributes
store[RW]
Public Class Methods
default_logger()
click to toggle source
# File lib/p3-tvdb/httparty_icebox.rb, line 125 def self.default_logger; logger = ::Logger.new(STDERR); end
logger()
click to toggle source
# File lib/p3-tvdb/httparty_icebox.rb, line 124 def self.logger; @logger || default_logger; end
logger=(device)
click to toggle source
Pass a filename (String), IO object, Logger instance or nil
to silence the logger
# File lib/p3-tvdb/httparty_icebox.rb, line 128 def self.logger=(device); @logger = device.kind_of?(::Logger) ? device : ::Logger.new(device); end
new(store, options={})
click to toggle source
# File lib/p3-tvdb/httparty_icebox.rb, line 114 def initialize(store, options={}) self.class.logger = options[:logger] @store = self.class.lookup_store(store).new(options) end
Private Class Methods
lookup_store(name)
click to toggle source
Return store class based on passed name
# File lib/p3-tvdb/httparty_icebox.rb, line 133 def self.lookup_store(name) store_name = "#{name.capitalize}Store" return Store::const_get(store_name) rescue NameError => e raise Store::StoreNotFound, "The cache store '#{store_name}' was not found. Did you loaded any such class?" end
Public Instance Methods
exists?(key)
click to toggle source
# File lib/p3-tvdb/httparty_icebox.rb, line 121 def exists?(key); @store.exists? encode(key); end
get(key)
click to toggle source
# File lib/p3-tvdb/httparty_icebox.rb, line 119 def get(key); @store.get encode(key) unless stale?(key); end
set(key, value)
click to toggle source
# File lib/p3-tvdb/httparty_icebox.rb, line 120 def set(key, value); @store.set encode(key), value; end
stale?(key)
click to toggle source
# File lib/p3-tvdb/httparty_icebox.rb, line 122 def stale?(key); @store.stale? encode(key); end
Private Instance Methods
encode(key)
click to toggle source
# File lib/p3-tvdb/httparty_icebox.rb, line 140 def encode(key); Digest::MD5.hexdigest(key); end