File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,10 @@ the cached reuslts to prevent unnecessary roundtrips to the database.
2020Usage
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
2628To 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.
You can’t perform that action at this time.
0 commit comments