Class: HTTParty::Icebox::Store::MemoryStore
- Inherits:
-
AbstractStore
- Object
- AbstractStore
- HTTParty::Icebox::Store::MemoryStore
- Defined in:
- lib/httparty-icebox.rb
Overview
Store objects in memory
See HTTParty::Icebox::ClassMethods.cache
Instance Method Summary collapse
- #exists?(key) ⇒ Boolean
- #get(key) ⇒ Object
-
#initialize(options = {}) ⇒ MemoryStore
constructor
A new instance of MemoryStore.
- #set(key, value) ⇒ Object
- #stale?(key) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ MemoryStore
Returns a new instance of MemoryStore.
204 205 206 |
# File 'lib/httparty-icebox.rb', line 204 def initialize(={}) super; @store = {}; self end |
Instance Method Details
#exists?(key) ⇒ Boolean
216 217 218 |
# File 'lib/httparty-icebox.rb', line 216 def exists?(key) !@store[key].nil? end |
#get(key) ⇒ Object
211 212 213 214 215 |
# File 'lib/httparty-icebox.rb', line 211 def get(key) data = @store[key][1] Cache.logger.info("Cache: #{data.nil? ? "miss" : "hit"} (#{key})") data end |
#set(key, value) ⇒ Object
207 208 209 210 |
# File 'lib/httparty-icebox.rb', line 207 def set(key, value) Cache.logger.info("Cache: set (#{key})") @store[key] = [Time.now, value]; true end |
#stale?(key) ⇒ Boolean
219 220 221 222 |
# File 'lib/httparty-icebox.rb', line 219 def stale?(key) return true unless exists?(key) Time.now - created(key) > @timeout end |