Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6202

Show
Ignore:
Timestamp:
02/22/07 08:14:47 (2 years ago)
Author:
bitsweat
Message:

Use the query cache iff Active Record is configured.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/query_cache.rb

    r6195 r6202  
    8888        query_caches[self] = cache 
    8989      end 
    90              
    91       def cache         
    92         self.query_cache = QueryCache.new(connection_without_query_cache) 
    93         yield 
    94       ensure  
    95         self.query_cache = nil 
    96       end         
    97        
     90 
     91      # Use a query cache within the given block. 
     92      def cache 
     93        # Don't cache if Active Record is not configured. 
     94        if ActiveRecord::Base.configurations.blank? 
     95          yield 
     96        else 
     97          begin 
     98            self.query_cache = QueryCache.new(connection_without_query_cache) 
     99            yield 
     100          ensure 
     101            self.query_cache = nil 
     102          end 
     103        end 
     104      end 
     105 
    98106      def connection 
    99107        query_cache || connection_without_query_cache