Module: ActiveRecord::Caching

Defined in:
lib/cachear.rb

Overview

ActiveRecord::MemoryCache.logger = ActiveRecord::Base.logger ActiveRecord::Base.cacher = ActiveRecord::MemoryCache.instance

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.append_features(base) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/cachear.rb', line 17

def self.append_features(base)    
   super     
   base.class_eval do     
     cattr_accessor :cacher              
     class << self
       alias_method :ar_find_by_sql, :find_by_sql
       alias_method :ar_count_by_sql, :count_by_sql
       undef :find_by_sql, :count_by_sql
       
       def find_by_sql(sql)
         cacher.cache_query( self, sanitize_sql(sql) ) do |s|
           ar_find_by_sql(s)
         end
       end  
       
       def count_by_sql(sql)
          cacher.cache_query( self, sanitize_sql(sql) ) do |s|
            ar_count_by_sql(s)
          end
       end
       
       def ===(inst)
         i = 0
         while( (kl = inst.class.ancestors[i]) != Object )
          return true if self.to_s == kl.to_s
          i += 1
         end
         super
       end
                         
     end            
     
   end
   
end

Instance Method Details

#after_saveObject



62
63
64
# File 'lib/cachear.rb', line 62

def after_save
  self.class.cacher.expire(self.class)
end

#is_a?(klass) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/cachear.rb', line 58

def is_a?(klass)
  kind_of?(klass)
end

#kind_of?(klass) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/cachear.rb', line 53

def kind_of?(klass)
   return true if klass === self
   super
end