class Mongo::QueryCache::Middleware

Rack middleware that activates the query cache for each request.

Public Class Methods

new(app) click to toggle source

Instantiate the middleware.

@example Create the new middleware.

Middleware.new(app)

@param [ Object ] app The rack application stack.

# File lib/mongo/query_cache.rb, line 263
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source

Enable query cache and execute the request.

@example Execute the request.

middleware.call(env)

@param [ Object ] env The environment.

@return [ Object ] The result of the call.

# File lib/mongo/query_cache.rb, line 275
def call(env)
  QueryCache.cache do
    @app.call(env)
  end
ensure
  QueryCache.clear
end