Class: WarpCore::Cache
- Inherits:
-
Object
- Object
- WarpCore::Cache
- Defined in:
- lib/warpcore/cache.rb
Class Attribute Summary collapse
-
.store ⇒ Object
Returns the value of attribute store.
Class Method Summary collapse
- .get(key, opts = {}, block = nil) ⇒ Object
- .set(key, value, opts = {}) ⇒ Object
- .setup(moneta, opts = {}) ⇒ Object
Class Attribute Details
.store ⇒ Object
Returns the value of attribute store.
17 18 19 |
# File 'lib/warpcore/cache.rb', line 17 def store @store end |
Class Method Details
.get(key, opts = {}, block = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/warpcore/cache.rb', line 23 def get(key, opts = {}, block = nil) block = Proc.new if block_given? && block.nil? valid = block.respond_to?(:call) if @store.nil? return valid ? block.call(key) : nil end return @store[key] unless block.respond_to?(:call) opts[:expires] = opts[:expires].to_i if opts[:expires].present? @store.fetch(key, opts) do |key| val = block.call(key) self.set(key, val, opts) end rescue Exception => e warn "[WarpCore::Cache] Fetch Error => #{e}" block.respond_to?(:call) ? block.call(key) : nil end |
.set(key, value, opts = {}) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/warpcore/cache.rb', line 40 def set(key,value, opts = {}) @store&.store(key, value, opts) || value rescue Exception => e warn "[WarpCore::Cache] Store Error => #{e}" value end |
.setup(moneta, opts = {}) ⇒ Object
19 20 21 |
# File 'lib/warpcore/cache.rb', line 19 def setup(moneta, opts = {}) @store = moneta end |