Skip to content

Commit 78c61b2

Browse files
p-mongop
andauthored
RUBY-2411 Port query cache middleware to driver
(#2165) * RUBY-2411 Port query cache middleware to driver * fix typos Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent 5f52bdb commit 78c61b2

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

source/tutorials/query-cache.txt

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ the cached reuslts to prevent unnecessary roundtrips to the database.
2020
Usage
2121
=====
2222

23-
The query cache is disabled by default. It cache can be enabled on the global
24-
scope as well as within the context of a specific block.
23+
The query cache is disabled by default. It can be enabled on the global
24+
scope as well as within the context of a specific block. The driver also
25+
provides a :ref:`Rack middleware <query-cache-middleware>` to enable the
26+
query cache automatically for each web request.
2527

2628
To enable the query cache globally:
2729

@@ -231,3 +233,24 @@ You may read more about system collections in the
231233
Even when the query cache is enabled, query results from system collections
232234
will not be cached.
233235

236+
237+
.. _query-cache-middleware:
238+
239+
Query Cache Middleware
240+
======================
241+
242+
The driver provides a Rack middleware which enables the query cache for the
243+
duration of each web request. Below is an example of how to enable the
244+
query cache middleware in a Ruby on Rails application:
245+
246+
.. code-block:: ruby
247+
248+
# config/application.rb
249+
250+
# Add Mongo::QueryCache::Middleware at the bottom of the middleware stack
251+
# or before other middleware that queries MongoDB.
252+
config.middleware.use Mongo::QueryCache::Middleware
253+
254+
Please refer to the `Rails on Rack guide
255+
<https://guides.rubyonrails.org/rails_on_rack.html#configuring-middleware-stack>`_
256+
for more information about using Rack middleware in Rails applications.

0 commit comments

Comments
 (0)