Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 50 lines (43 sloc) 1.381 kb
76f024a @fxn adds missing requires for Object#blank? and Object#present?
fxn authored
1 require 'active_support/core_ext/object/blank'
2
cce294f @dhh Started work on a per-request query cache
dhh authored
3 module ActiveRecord
2b7f084 @rizwanreza Adds basic description and title.
rizwanreza authored
4 # = Active Record Query Cache
aa002c0 @josh ActiveRecord::QueryCache middleware
josh authored
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
f425bba @jeremy Use the query cache iff Active Record is configured.
jeremy authored
14 end
aa002c0 @josh ActiveRecord::QueryCache middleware
josh authored
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
bfb906a @jeremy Speed up and simplify query caching.
jeremy authored
28 end
f425bba @jeremy Use the query cache iff Active Record is configured.
jeremy authored
29
2b81240 @lest use Rack::BodyProxy in activerecord middlewares
lest authored
30 def call(env)
31 enabled = ActiveRecord::Base.connection.query_cache_enabled
32 connection_id = ActiveRecord::Base.connection_id
33 ActiveRecord::Base.connection.enable_query_cache!
951e18a @tenderlove introduce a body proxy to ensure that query cache is enabled during s…
tenderlove authored
34
2b81240 @lest use Rack::BodyProxy in activerecord middlewares
lest authored
35 response = @app.call(env)
36 response[2] = Rack::BodyProxy.new(response[2]) do
37 ActiveRecord::Base.connection_id = connection_id
38d92d7 @tenderlove ensure query cache is cleared when Rack body is closed, fixes bug rep…
tenderlove authored
38 ActiveRecord::Base.connection.clear_query_cache
2b81240 @lest use Rack::BodyProxy in activerecord middlewares
lest authored
39 ActiveRecord::Base.connection.disable_query_cache! unless enabled
7117fdb @jeremy r3616@asus: jeremy | 2005-09-26 23:09:28 -0700
jeremy authored
40 end
951e18a @tenderlove introduce a body proxy to ensure that query cache is enabled during s…
tenderlove authored
41
2b81240 @lest use Rack::BodyProxy in activerecord middlewares
lest authored
42 response
b4ff82a @tenderlove clear and disable query cache when an exception is raised from called…
tenderlove authored
43 rescue Exception => e
44 ActiveRecord::Base.connection.clear_query_cache
2b81240 @lest use Rack::BodyProxy in activerecord middlewares
lest authored
45 ActiveRecord::Base.connection.disable_query_cache! unless enabled
b4ff82a @tenderlove clear and disable query cache when an exception is raised from called…
tenderlove authored
46 raise e
951e18a @tenderlove introduce a body proxy to ensure that query cache is enabled during s…
tenderlove authored
47 end
bfb906a @jeremy Speed up and simplify query caching.
jeremy authored
48 end
cce294f @dhh Started work on a per-request query cache
dhh authored
49 end
Something went wrong with that request. Please try again.