Class: Lawnchair::StorageEngine::Abstract
- Inherits:
-
Object
- Object
- Lawnchair::StorageEngine::Abstract
- Defined in:
- lib/storage_engine/abstract.rb
Class Attribute Summary collapse
-
.data_store ⇒ Object
readonly
Returns the value of attribute data_store.
Class Method Summary collapse
- .computed_key(key) ⇒ Object
- .db_connection? ⇒ Boolean
- .fetch(key, options = {}, &block) ⇒ Object
- .get(key, options = {}) ⇒ Object
- .log(message, key, elapsed) ⇒ Object
Class Attribute Details
.data_store ⇒ Object (readonly)
Returns the value of attribute data_store.
5 6 7 |
# File 'lib/storage_engine/abstract.rb', line 5 def data_store @data_store end |
Class Method Details
.computed_key(key) ⇒ Object
33 34 35 36 37 |
# File 'lib/storage_engine/abstract.rb', line 33 def computed_key(key) raise "Missing key" if key.nil? || key.empty? prefix = "Lawnchair" "#{prefix}:#{key}" end |
.db_connection? ⇒ Boolean
39 40 41 |
# File 'lib/storage_engine/abstract.rb', line 39 def db_connection? true end |
.fetch(key, options = {}, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/storage_engine/abstract.rb', line 11 def fetch(key, ={}, &block) start_time = Time.now if value = get(key, ) log("HIT", key, Time.now-start_time) return value else value = block.call set(key, value, ) log("MISS", key, Time.now-start_time) return value end end |
.get(key, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/storage_engine/abstract.rb', line 24 def get(key, ={}) if [:raw] data_store[computed_key(key)] else value = data_store[computed_key(key)] value.nil? ? nil : Marshal.load(value) end end |
.log(message, key, elapsed) ⇒ Object
43 44 45 46 |
# File 'lib/storage_engine/abstract.rb', line 43 def log(, key, elapsed) Lawnchair.redis.hincrby(, computed_key(key), 1) ActionController::Base.logger.info("Lawnchair Cache: #{} (%0.6f secs): #{key}" % elapsed) if defined? ::ActionController::Base end |