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

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