Module: Cacheable::MethodCache

Included in:
Caches
Defined in:
lib/cacheable/types/method_cache.rb

Instance Method Summary collapse

Instance Method Details

#with_method(*methods) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cacheable/types/method_cache.rb', line 3

def with_method(*methods)
  self.cached_methods = methods

  class_eval do
    after_commit :expire_method_cache, :on => :update
  end

  methods.each do |meth|
    define_method("cached_#{meth}") do
      Rails.cache.fetch method_cache_key(meth) do
        send(meth)
      end
    end
  end
end