class WarpCore::Cache
A class helper to manage a Moneta cache store that can be used throughout the system.
Attributes
store[RW]
Public Class Methods
get(key, opts = {}, block = nil)
click to toggle source
# File lib/warpcore/cache.rb, line 25 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 = {})
click to toggle source
# File lib/warpcore/cache.rb, line 42 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 = {})
click to toggle source
# File lib/warpcore/cache.rb, line 21 def setup(moneta, opts = {}) @store = moneta end