Class: Mongoid::QueryCache::Middleware

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

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Instantiate the middleware.

Examples:

Create the new middleware.

Middleware.new(app)

Parameters:

  • app (Object)

    The rack application stack.



130
131
132
# File 'lib/mongoid/query_cache.rb', line 130

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

Execute the request, wrapping in a query cache.

Examples:

Execute the request.

middleware.call(env)

Parameters:

  • env (Object)

    The environment.

Returns:

  • (Object)

    The result of the call.



142
143
144
145
146
147
148
# File 'lib/mongoid/query_cache.rb', line 142

def call(env)
  QueryCache.cache do
    @app.call(env)
  end
ensure
  QueryCache.clear_cache
end