Class: HTTParty::Icebox::Cache
- Inherits:
-
Object
- Object
- HTTParty::Icebox::Cache
- Defined in:
- lib/filmbuff/httparty_icebox.rb
Overview
Cache container
Pass a store name (‘memory’, etc) to new
Instance Attribute Summary collapse
-
#store ⇒ Object
Returns the value of attribute store.
Class Method Summary collapse
- .default_logger ⇒ Object
- .logger ⇒ Object
-
.logger=(device) ⇒ Object
Pass a filename (String), IO object, Logger instance or
nil
to silence the logger.
Instance Method Summary collapse
- #exists?(key) ⇒ Boolean
- #get(key) ⇒ Object
-
#initialize(store, options = {}) ⇒ Cache
constructor
A new instance of Cache.
- #set(key, value) ⇒ Object
- #stale?(key) ⇒ Boolean
Constructor Details
#initialize(store, options = {}) ⇒ Cache
Returns a new instance of Cache.
117 118 119 120 |
# File 'lib/filmbuff/httparty_icebox.rb', line 117 def initialize(store, ={}) self.class.logger = [:logger] @store = self.class.lookup_store(store).new() end |
Instance Attribute Details
#store ⇒ Object
Returns the value of attribute store.
115 116 117 |
# File 'lib/filmbuff/httparty_icebox.rb', line 115 def store @store end |
Class Method Details
.default_logger ⇒ Object
143 144 145 |
# File 'lib/filmbuff/httparty_icebox.rb', line 143 def self.default_logger logger = ::Logger.new(STDERR) end |
.logger ⇒ Object
139 140 141 |
# File 'lib/filmbuff/httparty_icebox.rb', line 139 def self.logger @logger || default_logger end |
.logger=(device) ⇒ Object
Pass a filename (String), IO object, Logger instance or nil
to silence the logger
148 149 150 |
# File 'lib/filmbuff/httparty_icebox.rb', line 148 def self.logger=(device) @logger = device.kind_of?(::Logger) ? device : ::Logger.new(device) end |
Instance Method Details
#exists?(key) ⇒ Boolean
131 132 133 |
# File 'lib/filmbuff/httparty_icebox.rb', line 131 def exists?(key) @store.exists? encode(key) end |
#get(key) ⇒ Object
122 123 124 |
# File 'lib/filmbuff/httparty_icebox.rb', line 122 def get(key) @store.get encode(key) unless stale?(key) end |
#set(key, value) ⇒ Object
126 127 128 129 |
# File 'lib/filmbuff/httparty_icebox.rb', line 126 def set(key, value) # puts "Cache.set, key: #{key}, value: #{value}" @store.set encode(key), value end |
#stale?(key) ⇒ Boolean
135 136 137 |
# File 'lib/filmbuff/httparty_icebox.rb', line 135 def stale?(key) @store.stale? encode(key) end |