Class: HTTParty::Icebox::Store::MemoryStore

Inherits:
AbstractStore show all
Defined in:
lib/filmbuff/httparty_icebox.rb

Overview

Store objects in memory

See HTTParty::Icebox::ClassMethods.cache

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MemoryStore

Returns a new instance of MemoryStore.



196
197
198
# File 'lib/filmbuff/httparty_icebox.rb', line 196

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

Instance Method Details

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


208
209
210
# File 'lib/filmbuff/httparty_icebox.rb', line 208

def exists?(key)
  !@store[key].nil?
end

#get(key) ⇒ Object



203
204
205
206
207
# File 'lib/filmbuff/httparty_icebox.rb', line 203

def get(key)
  data = @store[key][1]
  Cache.logger.info("Cache: #{data.nil? ? "miss" : "hit"} (#{key})")
  data
end

#set(key, value) ⇒ Object



199
200
201
202
# File 'lib/filmbuff/httparty_icebox.rb', line 199

def set(key, value)
  Cache.logger.info("Cache: set (#{key})")
  @store[key] = [Time.now, value]; true
end

#stale?(key) ⇒ Boolean

Returns:

  • (Boolean)


211
212
213
214
# File 'lib/filmbuff/httparty_icebox.rb', line 211

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