Sha256: 719bde9722dc2b0d441ff3e24eeabd9922143e08702bb551cb69bb1d25d9c4ce

Contents?: true

Size: 1.62 KB

Versions: 33

Compression:

Stored size: 1.62 KB

Contents

module ActiveRecord
  class QueryCache #:nodoc:
    def initialize(connection)
      @connection = connection
      @query_cache = {}
    end

    def clear_query_cache
      @query_cache = {}
    end

    def select_all(sql, name = nil)
      (@query_cache[sql] ||= @connection.select_all(sql, name)).dup
    end

    def select_one(sql, name = nil)
      @query_cache[sql] ||= @connection.select_one(sql, name)
    end

    def columns(table_name, name = nil)
      @query_cache["SHOW FIELDS FROM #{table_name}"] ||= @connection.columns(table_name, name)
    end

    def insert(sql, name = nil, pk = nil, id_value = nil)
      clear_query_cache
      @connection.insert(sql, name, pk, id_value)
    end

    def update(sql, name = nil)
      clear_query_cache
      @connection.update(sql, name)
    end

    def delete(sql, name = nil)
      clear_query_cache
      @connection.delete(sql, name)
    end
    
    private
      def method_missing(method, *arguments, &proc)
        @connection.send(method, *arguments, &proc)
      end
  end
  
  class Base
    # Set the connection for the class with caching on
    class << self
      alias_method :connection_without_query_cache=, :connection=

      def connection=(spec)
        if spec.is_a?(ConnectionSpecification) and spec.config[:query_cache]
          spec = QueryCache.new(self.send(spec.adapter_method, spec.config))
        end
        self.connection_without_query_cache = spec
      end
    end
  end
  
  class AbstractAdapter #:nodoc:
    # Stub method to be able to treat the connection the same whether the query cache has been turned on or not
    def clear_query_cache
    end
  end
end

Version data entries

33 entries across 33 versions & 5 rubygems

Version Path
jstorimer-deep-test-2.0.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/query_cache.rb
jstorimer-deep-test-1.4.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/query_cache.rb
jstorimer-deep-test-1.3.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/query_cache.rb
jstorimer-deep-test-1.2.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/query_cache.rb
jstorimer-deep-test-1.1.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/query_cache.rb
jstorimer-deep-test-1.0.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/query_cache.rb
jstorimer-deep-test-0.2.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/query_cache.rb
jstorimer-deep-test-0.1.0 sample_rails_project/vendor/rails/activerecord/lib/active_record/query_cache.rb
activerecord-1.13.0 lib/active_record/query_cache.rb
activerecord-1.12.2 lib/active_record/query_cache.rb
activerecord-1.12.1 lib/active_record/query_cache.rb
activerecord-1.14.1 lib/active_record/query_cache.rb
activerecord-1.14.3 lib/active_record/query_cache.rb
activerecord-1.14.2 lib/active_record/query_cache.rb
activerecord-1.14.0 lib/active_record/query_cache.rb
activerecord-1.13.1 lib/active_record/query_cache.rb
activerecord-1.13.2 lib/active_record/query_cache.rb
activerecord-1.15.1 lib/active_record/query_cache.rb
activerecord-1.15.4 lib/active_record/query_cache.rb
activerecord-1.15.2 lib/active_record/query_cache.rb