Class: ActionSubscriber::Middleware::ActiveRecord::QueryCache

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ QueryCache

Returns a new instance of QueryCache.



5
6
7
# File 'lib/action_subscriber/middleware/active_record/query_cache.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/action_subscriber/middleware/active_record/query_cache.rb', line 9

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

  @app.call(env)
ensure
  restore_query_cache_settings(connection_id, enabled)
end