Module: RailheadCacheify::ClassMethods

Defined in:
lib/railhead_cacheify.rb

Instance Method Summary collapse

Instance Method Details

#cacheify(key, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/railhead_cacheify.rb', line 29

def cacheify(key, options = {})
  class_eval <<-END
    alias _original_#{key} #{key}
    def #{key}(*args)
      @#{key} ||= read_cache(:#{key}, #{options[:expires_in] ? "{expires_in: #{options[:expires_in]}}" : '{}'}) { _original_#{key}(*args) }
    end
  END
end