Skip to content
This repository
Newer
Older
100644 72 lines (62 sloc) 1.878 kb
76f024ac » fxn
2010-03-28 adds missing requires for Object#blank? and Object#present?
1 require 'active_support/core_ext/object/blank'
2
cce294fd » dhh
2005-05-02 Started work on a per-request query cache
3 module ActiveRecord
2b7f0842 » rizwanreza
2010-06-16 Adds basic description and title.
4 # = Active Record Query Cache
aa002c0e » josh
2008-12-22 ActiveRecord::QueryCache middleware
5 class QueryCache
6 module ClassMethods
7 # Enable the query cache within the block if Active Record is configured.
8 def cache(&block)
9 if ActiveRecord::Base.configurations.blank?
10 yield
11 else
12 connection.cache(&block)
13 end
f425bba9 » jeremy
2007-02-22 Use the query cache iff Active Record is configured.
14 end
aa002c0e » josh
2008-12-22 ActiveRecord::QueryCache middleware
15
16 # Disable the query cache within the block if Active Record is configured.
17 def uncached(&block)
18 if ActiveRecord::Base.configurations.blank?
19 yield
20 else
21 connection.uncached(&block)
22 end
23 end
24 end
25
26 def initialize(app)
27 @app = app
bfb906a9 » jeremy
2007-09-17 Speed up and simplify query caching.
28 end
f425bba9 » jeremy
2007-02-22 Use the query cache iff Active Record is configured.
29
951e18ab » tenderlove
2011-05-02 introduce a body proxy to ensure that query cache is enabled during s…
30 class BodyProxy # :nodoc:
31 def initialize(original_cache_value, target)
32 @original_cache_value = original_cache_value
33 @target = target
34 end
35
50444204 » stevehodgkiss
2011-06-18 Fix inconsistencies by being polite to the wrapped body. Needed for R…
36 def method_missing(method_sym, *arguments, &block)
37 @target.send(method_sym, *arguments, &block)
38 end
39
40 def respond_to?(method_sym, include_private = false)
41 super || @target.respond_to?(method_sym)
42 end
43
951e18ab » tenderlove
2011-05-02 introduce a body proxy to ensure that query cache is enabled during s…
44 def each(&block)
45 @target.each(&block)
46 end
47
48 def close
49 @target.close if @target.respond_to?(:close)
50 ensure
38d92d70 » tenderlove
2011-05-04 ensure query cache is cleared when Rack body is closed, fixes bug rep…
51 ActiveRecord::Base.connection.clear_query_cache
951e18ab » tenderlove
2011-05-02 introduce a body proxy to ensure that query cache is enabled during s…
52 unless @original_cache_value
53 ActiveRecord::Base.connection.disable_query_cache!
54 end
7117fdb8 » jeremy
2005-10-16 r3616@asus: jeremy | 2005-09-26 23:09:28 -0700
55 end
cce294fd » dhh
2005-05-02 Started work on a per-request query cache
56 end
951e18ab » tenderlove
2011-05-02 introduce a body proxy to ensure that query cache is enabled during s…
57
58 def call(env)
59 old = ActiveRecord::Base.connection.query_cache_enabled
60 ActiveRecord::Base.connection.enable_query_cache!
61
62 status, headers, body = @app.call(env)
63 [status, headers, BodyProxy.new(old, body)]
b4ff82a7 » tenderlove
2011-08-28 clear and disable query cache when an exception is raised from called…
64 rescue Exception => e
65 ActiveRecord::Base.connection.clear_query_cache
66 unless old
67 ActiveRecord::Base.connection.disable_query_cache!
68 end
69 raise e
951e18ab » tenderlove
2011-05-02 introduce a body proxy to ensure that query cache is enabled during s…
70 end
bfb906a9 » jeremy
2007-09-17 Speed up and simplify query caching.
71 end
cce294fd » dhh
2005-05-02 Started work on a per-request query cache
72 end
Something went wrong with that request. Please try again.