module Cacheable
Public Class Methods
respond_to?(method_sym, include_private = false)
click to toggle source
Calls superclass method
# File lib/model_cache/cacheable.rb, line 30 def self.respond_to?(method_sym, include_private = false) if method.to_s =~ /^cached_(.*)$/ true else super end end
Public Instance Methods
cache(cache_key, options = {}, &block)
click to toggle source
# File lib/model_cache/cacheable.rb, line 11 def cache(cache_key, options = {}, &block) cache_key = ActiveSupport::Cache.expand_cache_key (Array(cache_key) + [self, updated_at]) Rails.cache.fetch cache_key, options, &block end
method_missing(method, *arguments, &block)
click to toggle source
Calls superclass method
# File lib/model_cache/cacheable.rb, line 17 def method_missing(method, *arguments, &block) if method.to_s =~ /^cached_(.*)$/ cache $1 do value = send $1.to_sym value = value.to_a if value.is_a? ActiveRecord::Relation value end else super end end