Class: Mongoid::QueryCache::Middleware

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

Overview

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

Since:

  • 4.0.0

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 applciation stack.

Since:

  • 4.0.0



103
104
105
# File 'build/mongoid-7.0/lib/mongoid/query_cache.rb', line 103

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.

Since:

  • 4.0.0



117
118
119
120
121
# File 'build/mongoid-7.0/lib/mongoid/query_cache.rb', line 117

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