11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/acts_as_cachable.rb', line 11
def self.included(base)
base.module_eval do
def self.acts_as_cachable(options={})
default_configuration = {
:methods=>[:all,:first,:last]
}.merge(options)
default_configuration[:methods].each do |m|
next unless self.respond_to?(m.to_sym)
self.metaclass.send(:alias_method, "uncached_#{m}".to_sym, "#{m}".to_sym)
self.metaclass.send(:define_method,"self.#{m}".to_sym) do
Rails.cache.fetch("#{self.class.name}_#{m}") do
self.metaclass.send("uncached_#{m}".to_sym)
end
end
end
end
end
end
|