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
34 35 36 37 38 39 |
# File 'lib/storage_engine/abstract.rb', line 34 def computed_key(key) raise "Missing key" if key.nil? || key.empty? key.gsub!(" ","") if key.match(/\s/) prefix = "Lawnchair" "#{prefix}:#{key}" end |
.db_connection? ⇒ Boolean
41 42 43 |
# File 'lib/storage_engine/abstract.rb', line 41 def db_connection? true end |
.fetch(key, options = {}, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/storage_engine/abstract.rb', line 11 def fetch(key, ={}, &block) start_time = Time.now if exists?(key) 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
26 27 28 29 30 31 32 |
# File 'lib/storage_engine/abstract.rb', line 26 def get(key, ={}) if [:raw] data_store[computed_key(key)] else exists?(key) ? Marshal.load(data_store[computed_key(key)]) : nil end end |
.log(message, key, elapsed) ⇒ Object
45 46 47 |
# File 'lib/storage_engine/abstract.rb', line 45 def log(, key, elapsed) ActionController::Base.logger.info("Lawnchair Cache: #{} (%0.6f secs): #{key}" % elapsed) if defined? ::ActionController::Base end |