<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>test/testing_app/config/environments/development.rb</filename>
    </added>
    <added>
      <filename>test/testing_app/config/environments/production.rb</filename>
    </added>
    <added>
      <filename>test/testing_app/config/environments/test.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -14,9 +14,12 @@ If you want to install it like a git module you can follow this post, adapting t
 
 ## Requirements
 
-  - Ruby &gt;= 1.8.5
+  - Ruby &gt;= 1.8.4
+  
   - Rails &gt;= 2.1
+  
   - memcache-client gem (maybe it will work also in memcached gem by fauna, but I haven't tested it yet)
+  
   - MySQL or PostgreSQL
 
 ## Description
@@ -35,7 +38,23 @@ So, the version for the cache of that query will be the sum of the cache version
 
 The idea behind this is way of create and expire cache was inspired by the post [The Secret to Memcached](http://blog.leetsoft.com/2007/5/22/the-secret-to-memcached) by Tobias L&#252;tke.
 
-For this plugin to work it's supposed that your ActionController cache store configured is mem_cache_store. In not the plugin will not allow your application to start, raising an exception.
+For this plugin to work it's supposed that your ActionController cache store configured is `mem_cache_store`.
+
+I changed the behavior in one major way.  I made the memcaching of the QueryCache optional.  
+
+You need to add `_enable_memache_querycache_` to your AcitveRecord model, like so:
+
+&lt;code&gt;
+  class User &lt; ActiveRecord::Base
+    enable_memcache_querycache
+  end
+&lt;/code&gt;
+
+The reason for this (drastic) change is two fold:
+
+  - For starters, there are many tables where trying to cache the contents but expiring all caching on any insert/update/delete/drop/alter on the table causes unnecessary overhead.  A sessions table is a perfect example.  I also have a metrics table and a few other tables where the contents are changed _often_.  By not enabling memcache on tables that I know will constantly be changing I can save quite a number of needless memcache calls (not caching the session queries saves two reads and two writes per request).
+  
+  - The other reason is I don't quite trust the implications of having a persisted query cache.  I want to carefully roll it out, starting with just the few models that rarely change, and go from there.  I'm not worried about users seeing information they shouldn't be, as the key is the query; it is more about making sure things expire correctly.  I didn't want to push such a large caching change into my app without a careful (and long) rollout.
 
 ## Known issues
 
@@ -60,6 +79,9 @@ Also, it is possible to run in Rails &gt;= 1.2.4 if you change the plugin [query_ca
 ## Special Thanks
 
   - Raul Murciano &lt;http://raul.murciano.net/&gt; for helping to adapt the plugin to Rails 2.1
+  
   - methodmissing &lt;http://blog.methodmissing.com/&gt; for some fresh ideas, lock library and correct some mistakes
+  
+  - skippy &lt;http://github.com/skippy&gt; for a lot of work deleting and cleaning methods, and also doing this plugin optional to each model
 
 Copyright (c) 2008 [Fernando Blat](http://www.inwebwetrust.net), released under the MIT license</diff>
      <filename>README.markdown</filename>
    </modified>
    <modified>
      <diff>@@ -1,10 +1,6 @@
 = Running tests
 
-For testing this plugin I decided to adapt a big subset of ActiveRecord test suite in order to test if all those test run ok with the plugin activated.
-
-The main reason is because this plugin affects in a very deeper way the communication with the database. AR tests are very complete, and test everything concerned to the database: reads, updates, deletes, reads in relationships, creations through relations, etc
-
-That's why the test suite of this plugin is so different.
+For testing this plugin I decided to adapt a the query cache tests from ActiveRecord. 
 
 First of all you have to know that there is a Rails 2.1 application in test/testing_app. This application contains a lot of models. AR test suite has been converted to the Unit Tests of this application.
 
@@ -14,6 +10,8 @@ So you need a database as indicated in config/database.yml:
   adapter: mysql
   database: 'activerecord_unittest'
   encoding: utf8
+  
+And also a memcached running in the standar port (11211).
 
 Then, load the schema from db/schema.rb and run
 </diff>
      <filename>RUNNING_TESTS</filename>
    </modified>
    <modified>
      <diff>@@ -1,7 +1,6 @@
 = TODO
 
   - prevent race conditions [1], [2]. Test de library lock in lib/
-  - adapt the test query_cache_test in testing_app/
 
 [1] http://www.eu.socialtext.net/memcached/index.cgi?faq#race_conditions_and_stale_data
 [2] http://www.eu.socialtext.net/memcached/index.cgi?faq#emulating_locking_with_the_add_command</diff>
      <filename>TODO</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,3 @@
 if Object.const_defined?( 'ActionController' )
-  require 'query_memcached' if ActionController::Base.perform_caching
+  require 'query_memcached'
 end
\ No newline at end of file</diff>
      <filename>init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,12 +1,7 @@
 require 'digest/md5'
 
-unless defined?(::Rails.cache) || ::Rails.cache.class.is_a?(ActiveSupport::Cache::MemCacheStore)
-  warning = &quot;[Query memcached WARNING] ::Rails.cache is not defined or cache engine is not mem_cache_store&quot;
-  ActiveRecord::Base.logger.error warning
-  raise warning
-end
-
 module ActiveRecord
+  
   class Base
 
     # table_names is a special attribute that contains a regular expression with all the tables of the application
@@ -17,15 +12,32 @@ module ActiveRecord
     #     names, i.e, posts, comments and comments_posts. It is for make easier the regular expression
     #   - and finally, the regular expression is built
     cattr_accessor :table_names, :enableMemcacheQueryForModels
+    
     self.table_names = /#{connection.tables.sort_by { |c| c.length }.join('|')}/i
+    self.enableMemcacheQueryForModels ||= {}
 
     class &lt;&lt; self
+            
+      # put this class method at the top of your AR model to enable memcache for the queryCache, 
+      # otherwise it will use standard query cache
+      def enable_memcache_querycache(options = {})
+        if ActionController::Base.perform_caching &amp;&amp; defined?(::Rails.cache) &amp;&amp; ::Rails.cache.is_a?(ActiveSupport::Cache::MemCacheStore)
+          options[:expires_in] ||= 90.minutes
+          self.enableMemcacheQueryForModels[ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s] = options
+        else
+          warning = &quot;[Query memcached WARNING] Disabled for #{ActiveRecord::Base.send(:class_name_of_active_record_descendant, self)} -- Memcache for QueryCache is not enabled for this model because caching is not turned on, Rails.cache is not defined, or cache engine is not mem_cache_store&quot;
+          ActiveRecord::Base.logger.error warning
+        end
+      end
       
-      
-      # TODO: put this class method at the top of your AR model to enable memcache for the queryCache
-      def enable_memache_queryCache
+      def connection_with_memcache_query_cache
+        conn = connection_without_memcache_query_cache
+        conn.memcache_query_cache_options = self.enableMemcacheQueryForModels[self.to_s]
+        conn
       end
       
+      alias_method_chain :connection, :memcache_query_cache
+      
       def cache_version_key(table_name = nil)
         &quot;#{global_cache_version_key}/#{table_name || self.table_name}&quot;
       end
@@ -53,14 +65,19 @@ module ActiveRecord
   end
 
   module ConnectionAdapters # :nodoc:
+    
+    class AbstractAdapter
+      attr_accessor :memcache_query_cache_options
+    end
 
     class MysqlAdapter &lt; AbstractAdapter
       
       # alias_method_chain for expiring cache if necessary
       def execute_with_clean_query_cache(*args)
-        return execute_without_clean_query_cache(*args) unless query_cache_enabled
+        return execute_without_clean_query_cache(*args) unless self.memcache_query_cache_options &amp;&amp; query_cache_enabled
         sql = args[0].strip
         if sql =~ /^(INSERT|UPDATE|ALTER|DROP|DELETE)/i
+          # can only modify one table at a time...so stop after matching the first table name
           table_name = ActiveRecord::Base.extract_table_names(sql).first
           ActiveRecord::Base.increase_version!(table_name)
         end
@@ -74,19 +91,21 @@ module ActiveRecord
     class PostgreSQLAdapter &lt; AbstractAdapter
 
       def execute_with_clean_query_cache(*args)
+        return execute_without_clean_query_cache(*args) unless self.memcache_query_cache_options &amp;&amp; query_cache_enabled
         sql = args[0].strip
         if sql =~ /^(INSERT|UPDATE|ALTER|DROP|DELETE)/i
-          ActiveRecord::Base.extract_table_names(sql).each do |table_name|
-            ActiveRecord::Base.increase_version!(table_name)
-          end
+          table_name = ActiveRecord::Base.extract_table_names(sql).first
+          ActiveRecord::Base.increase_version!(table_name)
         end
         execute_without_clean_query_cache(*args)
       end
+      
       alias_method_chain :execute, :clean_query_cache
+      
     end
     
     module QueryCache
-
+    
       # Enable the query cache within the block
       def cache
         old, @query_cache_enabled = @query_cache_enabled, true
@@ -94,11 +113,10 @@ module ActiveRecord
         @cache_version ||= {}
         yield
       ensure
-        clear_query_cache
         @query_cache_enabled = old
+        clear_query_cache
       end
-
-
+    
       # Clears the query cache.
       #
       # One reason you may wish to call this method explicitly is between queries
@@ -109,64 +127,64 @@ module ActiveRecord
         @query_cache.clear if @query_cache
         @cache_version.clear if @cache_version
       end
-
+    
       private
-
-        def cache_sql(sql)
-          # priority order:
-          #  - if in @query_cache (memory of local app server) we prefer this
-          #  - else if exists in Memcached we prefer that
-          #  - else perform query in database and save memory caches
-          result =
-            if @query_cache.has_key?(sql)
-              log_info(sql, &quot;CACHE&quot;, 0.0)
-              @query_cache[sql]
-            elsif cached_result = ::Rails.cache.read(query_key(sql))
-              log_info(sql, &quot;MEMCACHE&quot;, 0.0)
-              @query_cache[sql] = cached_result
-            else
-              query_result = yield
-              @query_cache[sql] = query_result
-              ::Rails.cache.write(query_key(sql), query_result)
-              query_result
-            end
-
-          if Array === result
-            result.collect { |row| row.dup }
+    
+      def cache_sql(sql)
+        # priority order:
+        #  - if in @query_cache (memory of local app server) we prefer this
+        #  - else if exists in Memcached we prefer that
+        #  - else perform query in database and save memory caches
+        result =
+          if (query_cache_enabled || self.memcache_query_cache_options) &amp;&amp; @query_cache.has_key?(sql)
+            log_info(sql, &quot;CACHE&quot;, 0.0)
+            @query_cache[sql]
+          elsif self.memcache_query_cache_options &amp;&amp; cached_result = ::Rails.cache.read(query_key(sql), self.memcache_query_cache_options)
+            log_info(sql, &quot;MEMCACHE&quot;, 0.0)
+            @query_cache[sql] = cached_result
           else
-            result.duplicable? ? result.dup : result
+            query_result = yield
+            @query_cache[sql] = query_result if query_cache_enabled || self.memcache_query_cache_options            
+            ::Rails.cache.write(query_key(sql), query_result, self.memcache_query_cache_options) if self.memcache_query_cache_options
+            query_result
           end
-        rescue TypeError
-          result
-        end
-
-        # Transforms a sql query into a valid key for Memcache
-        def query_key(sql)
-          table_names = ActiveRecord::Base.extract_table_names(sql)
-          # version_number is the sum of the global version number and all 
-          # the version numbers of each table
-          version_number = get_cache_version # global version 
-          table_names.each { |table_name| version_number += get_cache_version(table_name) }
-          &quot;#{version_number}_#{Digest::MD5.hexdigest(sql)}&quot;
+    
+        if Array === result
+          result.collect { |row| row.dup }
+        else
+          result.duplicable? ? result.dup : result
         end
-
-        # Returns the cache version of a table_name. If table_name is empty its the global version
-        #
-        # We prefer to search for this key first in memory and then in Memcache
-        def get_cache_version(table_name = nil)
-          key_class_version = table_name ? ActiveRecord::Base.cache_version_key(table_name) : ActiveRecord::Base.global_cache_version_key
-          if @cache_version &amp;&amp; @cache_version[key_class_version]
-            @cache_version[key_class_version]
-          elsif version = ::Rails.cache.read(key_class_version)
-            @cache_version[key_class_version] = version if @cache_version
-            version
-          else
-            @cache_version[key_class_version] = 0 if @cache_version
-            ::Rails.cache.write(key_class_version, 0)
-            0
-          end
+      rescue TypeError
+        result
+      end
+    
+      # Transforms a sql query into a valid key for Memcache
+      def query_key(sql)
+        table_names = ActiveRecord::Base.extract_table_names(sql)
+        # version_number is the sum of the global version number and all 
+        # the version numbers of each table
+        version_number = get_cache_version # global version 
+        table_names.each { |table_name| version_number += get_cache_version(table_name) }
+        &quot;#{version_number}_#{Digest::MD5.hexdigest(sql)}&quot;
+      end
+    
+      # Returns the cache version of a table_name. If table_name is empty its the global version
+      #
+      # We prefer to search for this key first in memory and then in Memcache
+      def get_cache_version(table_name = nil)
+        key_class_version = table_name ? ActiveRecord::Base.cache_version_key(table_name) : ActiveRecord::Base.global_cache_version_key
+        if @cache_version &amp;&amp; @cache_version[key_class_version]
+          @cache_version[key_class_version]
+        elsif version = ::Rails.cache.read(key_class_version)
+          @cache_version[key_class_version] = version if @cache_version
+          version
+        else
+          @cache_version[key_class_version] = 0 if @cache_version
+          ::Rails.cache.write(key_class_version, 0)
+          0
         end
-
+      end
+    
     end
     
   end</diff>
      <filename>lib/query_memcached.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,256 +1 @@
-== Welcome to Rails
-
-Rails is a web-application framework that includes everything needed to create 
-database-backed web applications according to the Model-View-Control pattern. 
-
-This pattern splits the view (also called the presentation) into &quot;dumb&quot; templates
-that are primarily responsible for inserting pre-built data in between HTML tags.
-The model contains the &quot;smart&quot; domain objects (such as Account, Product, Person,
-Post) that holds all the business logic and knows how to persist themselves to
-a database. The controller handles the incoming requests (such as Save New Account,
-Update Product, Show Post) by manipulating the model and directing data to the view.
-
-In Rails, the model is handled by what's called an object-relational mapping
-layer entitled Active Record. This layer allows you to present the data from
-database rows as objects and embellish these data objects with business logic
-methods. You can read more about Active Record in
-link:files/vendor/rails/activerecord/README.html.
-
-The controller and view are handled by the Action Pack, which handles both
-layers by its two parts: Action View and Action Controller. These two layers
-are bundled in a single package due to their heavy interdependence. This is
-unlike the relationship between the Active Record and Action Pack that is much
-more separate. Each of these packages can be used independently outside of
-Rails.  You can read more about Action Pack in
-link:files/vendor/rails/actionpack/README.html.
-
-
-== Getting Started
-
-1. At the command prompt, start a new Rails application using the &lt;tt&gt;rails&lt;/tt&gt; command
-   and your application name. Ex: rails myapp
-2. Change directory into myapp and start the web server: &lt;tt&gt;script/server&lt;/tt&gt; (run with --help for options)
-3. Go to http://localhost:3000/ and get &quot;Welcome aboard: You're riding the Rails!&quot;
-4. Follow the guidelines to start developing your application
-
-
-== Web Servers
-
-By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise
-Rails will use WEBrick, the webserver that ships with Ruby. When you run script/server,
-Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
-that you can always get up and running quickly.
-
-Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
-suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
-getting up and running with mongrel is as easy as: &lt;tt&gt;gem install mongrel&lt;/tt&gt;.
-More info at: http://mongrel.rubyforge.org
-
-If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
-Mongrel and WEBrick and also suited for production use, but requires additional
-installation and currently only works well on OS X/Unix (Windows users are encouraged
-to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
-http://www.lighttpd.net.
-
-And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
-web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
-for production.
-
-But of course its also possible to run Rails on any platform that supports FCGI.
-Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
-please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
-
-
-== Apache .htaccess example
-
-# General Apache options
-AddHandler fastcgi-script .fcgi
-AddHandler cgi-script .cgi
-Options +FollowSymLinks +ExecCGI
-
-# If you don't want Rails to look in certain directories,
-# use the following rewrite rules so that Apache won't rewrite certain requests
-# 
-# Example:
-#   RewriteCond %{REQUEST_URI} ^/notrails.*
-#   RewriteRule .* - [L]
-
-# Redirect all requests not available on the filesystem to Rails
-# By default the cgi dispatcher is used which is very slow
-# 
-# For better performance replace the dispatcher with the fastcgi one
-#
-# Example:
-#   RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
-RewriteEngine On
-
-# If your Rails application is accessed via an Alias directive,
-# then you MUST also set the RewriteBase in this htaccess file.
-#
-# Example:
-#   Alias /myrailsapp /path/to/myrailsapp/public
-#   RewriteBase /myrailsapp
-
-RewriteRule ^$ index.html [QSA]
-RewriteRule ^([^.]+)$ $1.html [QSA]
-RewriteCond %{REQUEST_FILENAME} !-f
-RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
-
-# In case Rails experiences terminal errors
-# Instead of displaying this message you can supply a file here which will be rendered instead
-# 
-# Example:
-#   ErrorDocument 500 /500.html
-
-ErrorDocument 500 &quot;&lt;h2&gt;Application error&lt;/h2&gt;Rails application failed to start properly&quot;
-
-
-== Debugging Rails
-
-Sometimes your application goes wrong.  Fortunately there are a lot of tools that
-will help you debug it and get it back on the rails.
-
-First area to check is the application log files.  Have &quot;tail -f&quot; commands running
-on the server.log and development.log. Rails will automatically display debugging
-and runtime information to these files. Debugging info will also be shown in the
-browser on requests from 127.0.0.1.
-
-You can also log your own messages directly into the log file from your code using
-the Ruby logger class from inside your controllers. Example:
-
-  class WeblogController &lt; ActionController::Base
-    def destroy
-      @weblog = Weblog.find(params[:id])
-      @weblog.destroy
-      logger.info(&quot;#{Time.now} Destroyed Weblog ID ##{@weblog.id}!&quot;)
-    end
-  end
-
-The result will be a message in your log file along the lines of:
-
-  Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
-
-More information on how to use the logger is at http://www.ruby-doc.org/core/
-
-Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
-
-* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
-* Learn to Program: http://pine.fm/LearnToProgram/  (a beginners guide)
-
-These two online (and free) books will bring you up to speed on the Ruby language
-and also on programming in general.
-
-
-== Debugger
-
-Debugger support is available through the debugger command when you start your Mongrel or
-Webrick server with --debugger. This means that you can break out of execution at any point
-in the code, investigate and change the model, AND then resume execution! 
-You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
-Example:
-
-  class WeblogController &lt; ActionController::Base
-    def index
-      @posts = Post.find(:all)
-      debugger
-    end
-  end
-
-So the controller will accept the action, run the first line, then present you
-with a IRB prompt in the server window. Here you can do things like:
-
-  &gt;&gt; @posts.inspect
-  =&gt; &quot;[#&lt;Post:0x14a6be8 @attributes={\&quot;title\&quot;=&gt;nil, \&quot;body\&quot;=&gt;nil, \&quot;id\&quot;=&gt;\&quot;1\&quot;}&gt;,
-       #&lt;Post:0x14a6620 @attributes={\&quot;title\&quot;=&gt;\&quot;Rails you know!\&quot;, \&quot;body\&quot;=&gt;\&quot;Only ten..\&quot;, \&quot;id\&quot;=&gt;\&quot;2\&quot;}&gt;]&quot;
-  &gt;&gt; @posts.first.title = &quot;hello from a debugger&quot;
-  =&gt; &quot;hello from a debugger&quot;
-
-...and even better is that you can examine how your runtime objects actually work:
-
-  &gt;&gt; f = @posts.first
-  =&gt; #&lt;Post:0x13630c4 @attributes={&quot;title&quot;=&gt;nil, &quot;body&quot;=&gt;nil, &quot;id&quot;=&gt;&quot;1&quot;}&gt;
-  &gt;&gt; f.
-  Display all 152 possibilities? (y or n)
-
-Finally, when you're ready to resume execution, you enter &quot;cont&quot;
-
-
-== Console
-
-You can interact with the domain model by starting the console through &lt;tt&gt;script/console&lt;/tt&gt;.
-Here you'll have all parts of the application configured, just like it is when the
-application is running. You can inspect domain models, change values, and save to the
-database. Starting the script without arguments will launch it in the development environment.
-Passing an argument will specify a different environment, like &lt;tt&gt;script/console production&lt;/tt&gt;.
-
-To reload your controllers and models after launching the console run &lt;tt&gt;reload!&lt;/tt&gt;
-
-== dbconsole
-
-You can go to the command line of your database directly through &lt;tt&gt;script/dbconsole&lt;/tt&gt;.
-You would be connected to the database with the credentials defined in database.yml.
-Starting the script without arguments will connect you to the development database. Passing an
-argument will connect you to a different database, like &lt;tt&gt;script/dbconsole production&lt;/tt&gt;.
-Currently works for mysql, postgresql and sqlite.
-
-== Description of Contents
-
-app
-  Holds all the code that's specific to this particular application.
-
-app/controllers
-  Holds controllers that should be named like weblogs_controller.rb for
-  automated URL mapping. All controllers should descend from ApplicationController
-  which itself descends from ActionController::Base.
-
-app/models
-  Holds models that should be named like post.rb.
-  Most models will descend from ActiveRecord::Base.
-
-app/views
-  Holds the template files for the view that should be named like
-  weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
-  syntax.
-
-app/views/layouts
-  Holds the template files for layouts to be used with views. This models the common
-  header/footer method of wrapping views. In your views, define a layout using the
-  &lt;tt&gt;layout :default&lt;/tt&gt; and create a file named default.html.erb. Inside default.html.erb,
-  call &lt;% yield %&gt; to render the view using this layout.
-
-app/helpers
-  Holds view helpers that should be named like weblogs_helper.rb. These are generated
-  for you automatically when using script/generate for controllers. Helpers can be used to
-  wrap functionality for your views into methods.
-
-config
-  Configuration files for the Rails environment, the routing map, the database, and other dependencies.
-
-db
-  Contains the database schema in schema.rb.  db/migrate contains all
-  the sequence of Migrations for your schema.
-
-doc
-  This directory is where your application documentation will be stored when generated
-  using &lt;tt&gt;rake doc:app&lt;/tt&gt;
-
-lib
-  Application specific libraries. Basically, any kind of custom code that doesn't
-  belong under controllers, models, or helpers. This directory is in the load path.
-
-public
-  The directory available for the web server. Contains subdirectories for images, stylesheets,
-  and javascripts. Also contains the dispatchers and the default HTML files. This should be
-  set as the DOCUMENT_ROOT of your web server.
-
-script
-  Helper scripts for automation and generation.
-
-test
-  Unit and functional tests along with fixtures. When using the script/generate scripts, template
-  test files will be generated for you and placed in this directory.
-
-vendor
-  External libraries that the application depends on. Also includes the plugins subdirectory.
-  If the app has frozen rails, those gems also go here, under vendor/rails/.
-  This directory is in the load path.
+# Testing application from plugin Query Memcached
\ No newline at end of file</diff>
      <filename>test/testing_app/README</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
 class Computer &lt; ActiveRecord::Base
-  belongs_to :developer, :foreign_key=&gt;'developer'
+  enable_memcache_querycache
+  belongs_to :developer, :foreign_key =&gt; 'developer'
 end</diff>
      <filename>test/testing_app/app/models/computer.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,2 @@
 class Task &lt; ActiveRecord::Base
-
 end</diff>
      <filename>test/testing_app/app/models/task.rb</filename>
    </modified>
    <modified>
      <diff>@@ -11,7 +11,10 @@ Rails::Initializer.run do |config|
   config.cache_classes = false
   config.whiny_nils = true
   config.action_controller.perform_caching = true
-  config.cache_store = :test_store
+  config.cache_store = :mem_cache_store, { :servers =&gt; 'localhost:11211',
+                                           :namespace =&gt; 'testing_app',
+                                           :compression =&gt; true
+                                         }
 end
 
 require File.expand_path(File.dirname(__FILE__)) + &quot;/../../../lib/query_memcached&quot;
\ No newline at end of file</diff>
      <filename>test/testing_app/config/environment.rb</filename>
    </modified>
    <modified>
      <diff>@@ -48,23 +48,23 @@ class &lt;&lt; ActiveRecord::Base
   public :with_scope, :with_exclusive_scope
 end
 
-module Test
-  module Unit
-    class TestCase
-      
-
-      def run_with_query_memcached(*args, &amp;block)
-        Rails.cache.clear
-        ActiveRecord::Base.cache do 
-          run_without_query_memcached(*args, &amp;block)
-        end
-      end
-
-      alias_method_chain :run, :query_memcached
-
-    end
-  end
-end
+# module Test
+#   module Unit
+#     class TestCase
+#       
+# 
+#       def run_with_query_memcached(*args, &amp;block)
+#         Rails.cache.clear
+#         ActiveRecord::Base.cache do 
+#           run_without_query_memcached(*args, &amp;block)
+#         end
+#       end
+# 
+#       alias_method_chain :run, :query_memcached
+# 
+#     end
+#   end
+# end
 
 class Test::Unit::TestCase
   # Transactional fixtures accelerate your tests by wrapping each test method</diff>
      <filename>test/testing_app/test/test_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,122 +1,180 @@
-# TODO
-# adaptar a query_memcached
-
-# require File.dirname(__FILE__) + '/../test_helper'
-# 
-# class QueryCacheTest &lt; Test::Unit::TestCase
-#   fixtures :tasks, :topics, :categories, :posts, :categories_posts
-# 
-#   def test_find_queries
-#     assert_queries(2) { Task.find(1); Task.find(1) }
-#   end
-# 
-#   def test_find_queries_with_cache
-#     Task.cache do
-#       assert_queries(1) { Task.find(1); Task.find(1) }
-#     end
-#   end
-# 
-#   def test_count_queries_with_cache
-#     Task.cache do
-#       assert_queries(1) { Task.count; Task.count }
-#     end
-#   end
-# 
-#   def test_query_cache_dups_results_correctly
-#     Task.cache do
-#       now  = Time.now.utc
-#       task = Task.find 1
-#       assert_not_equal now, task.starting
-#       task.starting = now
-#       task.reload
-#       assert_not_equal now, task.starting
-#     end
-#   end
-# 
-#   def test_cache_is_flat
-#     Task.cache do
-#       Topic.columns # don't count this query
-#       assert_queries(1) { Topic.find(1); Topic.find(1); }
-#     end
-# 
-#     ActiveRecord::Base.cache do
-#       assert_queries(1) { Task.find(1); Task.find(1) }
-#     end
-#   end
-# 
-#   def test_cache_does_not_wrap_string_results_in_arrays
-#     Task.cache do
-#       assert_instance_of String, Task.connection.select_value(&quot;SELECT count(*) AS count_all FROM tasks&quot;)
-#     end
-#   end
-# end
-# 
-# uses_mocha 'QueryCacheExpiryTest' do
-# 
-# class QueryCacheExpiryTest &lt; Test::Unit::TestCase
-#   fixtures :tasks
-# 
-#   def test_find
-#     Task.connection.expects(:clear_query_cache).times(1)
-# 
-#     assert !Task.connection.query_cache_enabled
-#     Task.cache do
-#       assert Task.connection.query_cache_enabled
-#       Task.find(1)
-# 
-#       Task.uncached do
-#         assert !Task.connection.query_cache_enabled
-#         Task.find(1)
-#       end
-# 
-#       assert Task.connection.query_cache_enabled
-#     end
-#     assert !Task.connection.query_cache_enabled
-#   end
-# 
-#   def test_update
-#     Task.connection.expects(:clear_query_cache).times(2)
-# 
-#     Task.cache do
-#       task = Task.find(1)
-#       task.starting = Time.now.utc
-#       task.save!
-#     end
-#   end
-# 
-#   def test_destroy
-#     Task.connection.expects(:clear_query_cache).times(2)
-# 
-#     Task.cache do
-#       Task.find(1).destroy
-#     end
-#   end
-# 
-#   def test_insert
-#     ActiveRecord::Base.connection.expects(:clear_query_cache).times(2)
-# 
-#     Task.cache do
-#       Task.create!
-#     end
-#   end
-# 
-#   def test_cache_is_expired_by_habtm_update
-#     ActiveRecord::Base.connection.expects(:clear_query_cache).times(2)
-#     ActiveRecord::Base.cache do
-#       c = Category.find(:first)
-#       p = Post.find(:first)
-#       p.categories &lt;&lt; c
-#     end
-#   end
-# 
-#   def test_cache_is_expired_by_habtm_delete
-#     ActiveRecord::Base.connection.expects(:clear_query_cache).times(2)
-#     ActiveRecord::Base.cache do
-#       c = Category.find(:first)
-#       p = Post.find(:first)
-#       p.categories.delete_all
-#     end
-#   end
-# end
-# 
-# end
+require File.dirname(__FILE__) + '/../test_helper'
+
+class QueryCacheTest &lt; Test::Unit::TestCase
+  
+  fixtures :tasks, :topics, :categories, :posts, :categories_posts
+  
+  def test_find_queries
+    assert_queries(2) { Task.find(1); Task.find(1) }
+  end
+
+  def test_find_queries_with_query_memcache_enabled
+    Computer.cache do
+      assert_queries(1) { Computer.find(1); Computer.find(1) }
+    end
+  end
+
+  def test_find_queries_with_cache
+    Task.cache do
+      assert_queries(1) { Task.find(1); Task.find(1) }
+    end
+  end
+  
+  def test_count_queries_with_cache
+    Task.cache do
+      assert_queries(1) { Task.count; Task.count }
+    end
+  end
+  
+  def test_query_cache_dups_results_correctly
+    Task.cache do
+      now  = Time.now.utc
+      task = Task.find 1
+      assert_not_equal now, task.starting
+      task.starting = now
+      task.reload
+      assert_not_equal now, task.starting
+    end
+  end
+  
+  def test_cache_is_flat
+    Task.cache do
+      Topic.columns # don't count this query
+      assert_queries(1) { Topic.find(1); Topic.find(1); }
+    end
+  
+    ActiveRecord::Base.cache do
+      assert_queries(1) { Task.find(1); Task.find(1) }
+    end
+  end
+  
+  def test_cache_does_not_wrap_string_results_in_arrays
+    Task.cache do
+      assert_instance_of String, Task.connection.select_value(&quot;SELECT count(*) AS count_all FROM tasks&quot;)
+    end
+  end
+end
+
+uses_mocha 'QueryCacheExpiryTest' do
+
+class QueryCacheExpiryTest &lt; Test::Unit::TestCase
+  fixtures :tasks
+  
+  def setup
+    ::Rails.cache.clear
+  end
+
+  def test_find
+    Task.connection.expects(:clear_query_cache).times(1)
+
+    assert !Task.connection.query_cache_enabled
+    Task.cache do
+      assert Task.connection.query_cache_enabled
+      Task.find(1)
+
+      Task.uncached do
+        assert !Task.connection.query_cache_enabled
+        Task.find(1)
+      end
+
+      assert Task.connection.query_cache_enabled
+    end
+    assert !Task.connection.query_cache_enabled
+  end
+
+  def test_find_without_query_memcached_activated
+    ::Rails.cache.expects(:write).times(0)
+    ::Rails.cache.expects(:read).times(0)
+    Task.cache do
+      Task.find(1)
+      Task.find(1)
+    end
+  end
+  
+  def test_find_with_query_memcached_activated
+    # 3 writes:
+    # - version
+    # - version/computers
+    # - version/computers/1
+    ::Rails.cache.expects(:write).times(3)
+    # The same reads
+    ::Rails.cache.expects(:read).times(3)
+    Computer.cache do
+      Computer.find(1)
+      Computer.find(1)
+    end
+  end
+
+  def test_update
+    Task.connection.expects(:clear_query_cache).times(2)
+
+    Task.cache do
+      task = Task.find(1)
+      task.starting = Time.now.utc
+      task.save!
+    end
+  end
+  
+  def test_update_model_with_query_memcached_should_update_key
+    version = ::Rails.cache.read('version/computers') || 0
+    Computer.cache do
+      computer = Computer.find(1)
+      computer.developer = Developer.find(2)
+      computer.save!
+    end
+    assert_equal version + 1, ::Rails.cache.read('version/computers')
+  end
+  
+
+  def test_destroy
+    Task.connection.expects(:clear_query_cache).times(2)
+
+    Task.cache do
+      Task.find(1).destroy
+    end
+  end
+
+  def test_destroy_model_with_query_memcached_should_update_key
+    version = ::Rails.cache.read('version/computers') || 0
+    Computer.cache do
+      Computer.find(1).destroy
+    end
+    assert_equal version + 1, ::Rails.cache.read('version/computers')
+  end
+
+  def test_insert
+    ActiveRecord::Base.connection.expects(:clear_query_cache).times(2)
+
+    Task.cache do
+      Task.create!
+    end
+  end
+  
+  def test_insert_model_with_query_memcached_should_update_key
+    version = ::Rails.cache.read('version/computers') || 0
+    Computer.cache do
+      Computer.create!(:developer =&gt; Developer.find(1), :extendedWarranty =&gt; 1)
+    end
+    assert_equal version + 1, ::Rails.cache.read('version/computers')
+  end
+
+  def test_cache_is_expired_by_habtm_update
+    ActiveRecord::Base.connection.expects(:clear_query_cache).times(2)
+    ActiveRecord::Base.cache do
+      c = Category.find(:first)
+      p = Post.find(:first)
+      p.categories &lt;&lt; c
+    end
+  end
+
+  def test_cache_is_expired_by_habtm_delete
+    ActiveRecord::Base.connection.expects(:clear_query_cache).times(2)
+    ActiveRecord::Base.cache do
+      c = Category.find(:first)
+      p = Post.find(:first)
+      p.categories.delete_all
+    end
+  end
+end
+
+end</diff>
      <filename>test/testing_app/test/unit/query_cache_test.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>test/testing_app/doc/README_FOR_APP</filename>
    </removed>
    <removed>
      <filename>test/testing_app/lib/test_store.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/public/404.html</filename>
    </removed>
    <removed>
      <filename>test/testing_app/public/422.html</filename>
    </removed>
    <removed>
      <filename>test/testing_app/public/500.html</filename>
    </removed>
    <removed>
      <filename>test/testing_app/public/dispatch.cgi</filename>
    </removed>
    <removed>
      <filename>test/testing_app/public/dispatch.fcgi</filename>
    </removed>
    <removed>
      <filename>test/testing_app/public/dispatch.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/public/favicon.ico</filename>
    </removed>
    <removed>
      <filename>test/testing_app/public/images/rails.png</filename>
    </removed>
    <removed>
      <filename>test/testing_app/public/index.html</filename>
    </removed>
    <removed>
      <filename>test/testing_app/public/javascripts/application.js</filename>
    </removed>
    <removed>
      <filename>test/testing_app/public/javascripts/controls.js</filename>
    </removed>
    <removed>
      <filename>test/testing_app/public/javascripts/dragdrop.js</filename>
    </removed>
    <removed>
      <filename>test/testing_app/public/javascripts/effects.js</filename>
    </removed>
    <removed>
      <filename>test/testing_app/public/javascripts/prototype.js</filename>
    </removed>
    <removed>
      <filename>test/testing_app/public/robots.txt</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/aggregations_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/associations_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/attribute_methods_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/base_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/belongs_to_associations_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/calculations_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/callbacks_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/cascaded_eager_loading_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/date_time_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/defaults_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/dirty_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/eager_load_nested_include_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/eager_singularization_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/eager_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/extension_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/finder_respond_to_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/finder_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/has_and_belongs_to_many_associations_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/has_many_associations_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/has_many_through_associations_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/has_one_associations_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/has_one_through_associations_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/inner_join_association_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/join_model_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/lifecycle_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/locking_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/method_scoping_test.rb</filename>
    </removed>
    <removed>
      <filename>test/testing_app/test/unit/transactions_test.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>313653eaf309b680d971e8f68994e53d9c61516d</id>
    </parent>
  </parents>
  <author>
    <name>Fernando Blat Peris</name>
    <email>ferblape@gmail.com</email>
  </author>
  <url>http://github.com/ferblape/query_memcached/commit/3f54e208b750c2c5adca1bf5dbf80daf07303c68</url>
  <id>3f54e208b750c2c5adca1bf5dbf80daf07303c68</id>
  <committed-date>2008-12-21T09:36:42-08:00</committed-date>
  <authored-date>2008-12-21T09:36:42-08:00</authored-date>
  <message>Major changes:

  * **most important change**: now you have to indicate in each model if it's going to be cached or not. Please read the README for knowing how

  * fix some bugs and removed all and repeting code

  * improved tests: I have deleted all tests except all refering to Query Cache. Also, I have adapted them to the conditions of Query Memcached. Now it's necessary to have an instance of Memcached running</message>
  <tree>6370a5fb7b07693c6b9c7cf3352f02d4ea0926e8</tree>
  <committer>
    <name>Fernando Blat Peris</name>
    <email>ferblape@gmail.com</email>
  </committer>
</commit>
