Class: HTTParty::Icebox::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/howkast/ext/icebox.rb

Overview

Cache container

Pass a store name (‘memory’, etc) to initializer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store, options = {}) ⇒ Cache

Returns a new instance of Cache.



116
117
118
119
# File 'lib/howkast/ext/icebox.rb', line 116

def initialize(store, options={})
  self.class.logger = options[:logger]
  @store = self.class.lookup_store(store).new(options)
end

Instance Attribute Details

#storeObject

Returns the value of attribute store.



114
115
116
# File 'lib/howkast/ext/icebox.rb', line 114

def store
  @store
end

Class Method Details

.default_loggerObject



127
# File 'lib/howkast/ext/icebox.rb', line 127

def self.default_logger; logger = ::Logger.new(STDERR); end

.loggerObject



126
# File 'lib/howkast/ext/icebox.rb', line 126

def self.logger; @logger || default_logger; end

.logger=(device) ⇒ Object

Pass a filename (String), IO object, Logger instance or nil to silence the logger



130
# File 'lib/howkast/ext/icebox.rb', line 130

def self.logger=(device); @logger = device.kind_of?(::Logger) ? device : ::Logger.new(device); end

Instance Method Details

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


123
# File 'lib/howkast/ext/icebox.rb', line 123

def exists?(key);        @store.exists? encode(key);                       end

#get(key) ⇒ Object



121
# File 'lib/howkast/ext/icebox.rb', line 121

def get(key);            @store.get encode(key) unless stale?(key);        end

#set(key, value) ⇒ Object



122
# File 'lib/howkast/ext/icebox.rb', line 122

def set(key, value);     @store.set encode(key), value;                    end

#stale?(key) ⇒ Boolean

Returns:

  • (Boolean)


124
# File 'lib/howkast/ext/icebox.rb', line 124

def stale?(key);         @store.stale?  encode(key);                       end