Class: HTTParty::Icebox::Store::MemcachierStore

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

Overview

Store objects in memory

See HTTParty::Icebox::ClassMethods.cache

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MemcachierStore

Returns a new instance of MemcachierStore.



173
174
175
# File 'lib/httparty-icebox.rb', line 173

def initialize(options={})
  super; @store = {}; self
end

Instance Method Details

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


186
187
188
# File 'lib/httparty-icebox.rb', line 186

def exists?(key)
  Rails.cache.exist?(key)
end

#get(key) ⇒ Object



180
181
182
183
184
185
# File 'lib/httparty-icebox.rb', line 180

def get(key)
  data = Rails.cache.read(key)
  data = data[1] if !data.nil?
  Cache.logger.info("Cache: #{data.nil? ? "miss" : "hit"} (#{key})")
  data
end

#set(key, value) ⇒ Object



176
177
178
179
# File 'lib/httparty-icebox.rb', line 176

def set(key, value)
  Cache.logger.info("Cache: set (#{key})")
  Rails.cache.write(key, [Time.now, value]); true
end

#stale?(key) ⇒ Boolean

Returns:

  • (Boolean)


189
190
191
192
# File 'lib/httparty-icebox.rb', line 189

def stale?(key)
  return true unless exists?(key)
  Time.now - created(key) > @timeout
end