Class: OTR::ActiveRecord::QueryCache

Inherits:
Object
  • Object
show all
Defined in:
lib/otr-activerecord/middleware/query_cache.rb

Overview

Rack middleware to enable ActiveRecord’s query cache for each request.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ QueryCache

Returns a new instance of QueryCache.



7
8
9
# File 'lib/otr-activerecord/middleware/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
# File 'lib/otr-activerecord/middleware/query_cache.rb', line 11

def call(env)
  state = nil
  cache = defined?(::ActiveRecord::QueryCache::ExecutorHooks) ? ::ActiveRecord::QueryCache::ExecutorHooks : ::ActiveRecord::QueryCache
  state = cache.run
  @app.call(env)
ensure
  cache.complete(state) if state
end