Class: ActionSubscriber::Middleware::ActiveRecord::QueryCache
- Inherits:
-
Object
- Object
- ActionSubscriber::Middleware::ActiveRecord::QueryCache
- 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
- #call(env) ⇒ Object
-
#initialize(app) ⇒ QueryCache
constructor
A new instance of QueryCache.
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 |