Class: ActiveRecord::QueryCache

Inherits:
Object
  • Object
show all
Defined in:
activerecord/lib/active_record/query_cache.rb

Overview

Active Record Query Cache

Defined Under Namespace

Modules: ClassMethods Classes: BodyProxy

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ QueryCache



26
27
28
# File 'activerecord/lib/active_record/query_cache.rb', line 26

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'activerecord/lib/active_record/query_cache.rb', line 58

def call(env)
  old = ActiveRecord::Base.connection.query_cache_enabled
  ActiveRecord::Base.connection.enable_query_cache!

  status, headers, body = @app.call(env)
  [status, headers, BodyProxy.new(old, body)]
rescue Exception => e
  ActiveRecord::Base.connection.clear_query_cache
  unless old
    ActiveRecord::Base.connection.disable_query_cache!
  end
  raise e
end