0
@@ -4,7 +4,6 @@ module ActiveRecord
0
- attr_accessor :query_cache_enabled
0
alias_method_chain :columns, :query_cache
0
alias_method_chain :select_all, :query_cache
0
@@ -16,7 +15,7 @@ module ActiveRecord
0
method_names.each do |method_name|
0
base.class_eval <<-end_code, __FILE__, __LINE__
0
def #{method_name}_with_query_dirty(*args)
0
- clear_query_cache if
@query_cache_enabled
0
+ clear_query_cache if
query_cache_enabled
0
#{method_name}_without_query_dirty(*args)
0
@@ -26,22 +25,38 @@ module ActiveRecord
0
+ def query_cache_enabled
0
+ Thread.current['query_cache_enabled']
0
+ def query_cache_enabled=(flag)
0
+ Thread.current['query_cache_enabled'] = flag
0
+ Thread.current['query_cache']
0
+ def query_cache=(cache)
0
+ Thread.current['query_cache'] = cache
0
# Enable the query cache within the block.
0
- old, @query_cache_enabled = @query_cache_enabled, true
0
+ old, self.query_cache_enabled = query_cache_enabled, true
0
+ self.query_cache ||= {}
0
-
@query_cache_enabled = old
0
+
self.query_cache_enabled = old
0
# Disable the query cache within the block.
0
- old,
@query_cache_enabled = @query_cache_enabled, false
0
+ old,
self.query_cache_enabled = query_cache_enabled, false
0
-
@query_cache_enabled = old
0
+
self.query_cache_enabled = old
0
# Clears the query cache.
0
@@ -51,11 +66,11 @@ module ActiveRecord
0
# the same SQL query and repeatedly return the same result each time, silently
0
# undermining the randomness you were expecting.
0
-
@query_cache.clear if @query_cache
0
+
query_cache.clear if query_cache
0
def select_all_with_query_cache(*args)
0
- if
@query_cache_enabled
0
+ if
query_cache_enabled
0
cache_sql(args.first) { select_all_without_query_cache(*args) }
0
select_all_without_query_cache(*args)
0
@@ -63,8 +78,8 @@ module ActiveRecord
0
def columns_with_query_cache(*args)
0
- if @query_cache_enabled
0
- @query_cache["SHOW FIELDS FROM #{args.first}"] ||= columns_without_query_cache(*args)
0
+ if query_cache_enabled
0
+ query_cache["SHOW FIELDS FROM #{args.first}"] ||= columns_without_query_cache(*args)
0
columns_without_query_cache(*args)
0
@@ -73,11 +88,11 @@ module ActiveRecord
0
- if
@query_cache.has_key?(sql)
0
+ if
query_cache.has_key?(sql)
0
log_info(sql, "CACHE", 0.0)
0
-
@query_cache[sql] = yield
0
+
query_cache[sql] = yield