class Mongoid::QueryCache::Middleware

The middleware to be added to a rack application in order to activate the query cache.

@since 4.0.0

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.

@since 4.0.0

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

Public Instance Methods

call(env) click to toggle source

Execute the request, wrapping in a query cache.

@example Execute the request.

middleware.call(env)

@param [ Object ] env The environment.

@return [ Object ] The result of the call.

@since 4.0.0

# File lib/mongoid/query_cache.rb, line 161
def call(env)
  QueryCache.cache do
    @app.call(env)
  end
ensure
  QueryCache.clear_cache
end