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

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

Constant Summary collapse

CURRENT_CONNECTION =
"_action_subscriber_query_cache_current_connection".freeze

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ QueryCache

Returns a new instance of QueryCache.



7
8
9
# File 'lib/action_subscriber/middleware/active_record/query_cache.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  connection = ::Thread.current[CURRENT_CONNECTION] = ::ActiveRecord::Base.connection
  enabled = connection.query_cache_enabled
  connection.enable_query_cache!

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