Class: QueryCache::Middleware

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



15
16
17
# File 'lib/query_cache.rb', line 15

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/query_cache.rb', line 19

def call(env)
  connection = base.connection
  enabled = connection.query_cache_enabled
  connection_id = base.connection_id
  connection.enable_query_cache!

  response = @app.call(env)
  response[2] = Rack::BodyProxy.new(response[2]) do
    restore_query_cache_settings(connection_id, enabled)
  end

  response
ensure
  restore_query_cache_settings(connection_id, enabled)
end