Class: HTTParty::Icebox::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/httparty-icebox.rb

Overview

Cache container

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Cache.



103
104
105
106
# File 'lib/httparty-icebox.rb', line 103

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.



101
102
103
# File 'lib/httparty-icebox.rb', line 101

def store
  @store
end

Class Method Details

.default_loggerObject



125
# File 'lib/httparty-icebox.rb', line 125

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

.loggerObject



124
# File 'lib/httparty-icebox.rb', line 124

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

.logger=(device) ⇒ Object

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



128
# File 'lib/httparty-icebox.rb', line 128

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

Instance Method Details

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/httparty-icebox.rb', line 116

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

#get(key, force = false) ⇒ Object



108
109
110
# File 'lib/httparty-icebox.rb', line 108

def get(key, force=false)
  @store.get encode(key) if !stale?(key) || force
end

#set(key, value) ⇒ Object



112
113
114
# File 'lib/httparty-icebox.rb', line 112

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

#stale?(key) ⇒ Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/httparty-icebox.rb', line 120

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