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

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MemoryStore

Returns a new instance of MemoryStore.



175
176
177
# File 'lib/howkast/ext/icebox.rb', line 175

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

Instance Method Details

#exists?(key) ⇒ Boolean

Returns:

  • (Boolean)


187
188
189
# File 'lib/howkast/ext/icebox.rb', line 187

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

#get(key) ⇒ Object



182
183
184
185
186
# File 'lib/howkast/ext/icebox.rb', line 182

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

#set(key, value) ⇒ Object



178
179
180
181
# File 'lib/howkast/ext/icebox.rb', line 178

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

#stale?(key) ⇒ Boolean

Returns:

  • (Boolean)


190
191
192
193
# File 'lib/howkast/ext/icebox.rb', line 190

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