Class: HTTParty::Icebox::Store::MemoryStore
- Inherits:
-
AbstractStore
- Object
- AbstractStore
- HTTParty::Icebox::Store::MemoryStore
- Defined in:
- lib/rotten-party/httparty_icebox.rb
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.
173 174 175 |
# File 'lib/rotten-party/httparty_icebox.rb', line 173 def initialize(={}) super; @store = {}; self end |
Instance Method Details
#exists?(key) ⇒ Boolean
185 186 187 |
# File 'lib/rotten-party/httparty_icebox.rb', line 185 def exists?(key) !@store[key].nil? end |
#get(key) ⇒ Object
180 181 182 183 184 |
# File 'lib/rotten-party/httparty_icebox.rb', line 180 def get(key) data = @store[key][1] Cache.logger.info("Cache: #{data.nil? ? "miss" : "hit"} (#{key})") data end |
#set(key, value) ⇒ Object
176 177 178 179 |
# File 'lib/rotten-party/httparty_icebox.rb', line 176 def set(key, value) Cache.logger.info("Cache: set (#{key})") @store[key] = [Time.now, value]; true end |
#stale?(key) ⇒ Boolean
188 189 190 191 |
# File 'lib/rotten-party/httparty_icebox.rb', line 188 def stale?(key) return true unless exists?(key) Time.now - created(key) > @timeout end |