Class: QueryCache::Middleware

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

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware



17
18
19
# File 'lib/query_cache.rb', line 17

def initialize(app)
  @app = app
end

Class Attribute Details

.baseObject

Returns the value of attribute base.



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

def base
  @base
end

Class Method Details

.to_sObject



37
38
39
# File 'lib/query_cache.rb', line 37

def self.to_s
  base ? "#{superclass.name}<#{base.name}>" : name
end

Instance Method Details

#call(env) ⇒ Object



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

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