@@ -190,22 +190,66 @@ Toolbar options
190190
191191 Available store classes:
192192
193- * ``debug_toolbar.store.MemoryStore `` - Stores data in memory
194- * ``debug_toolbar.store.DatabaseStore `` - Stores data in the database
195-
196- The DatabaseStore provides persistence and automatically cleans up old
197- entries based on the ``RESULTS_CACHE_SIZE `` setting.
198-
199- Note: When using ``DatabaseStore `` migrations are required for
193+ * ``debug_toolbar.store.MemoryStore `` - Stores data in memory. This is the
194+ default and requires no additional configuration. Data is lost when the
195+ server restarts.
196+ * ``debug_toolbar.store.DatabaseStore `` - Stores data in the database.
197+ Requires running migrations (see below).
198+ * ``debug_toolbar.store.CacheStore `` - Stores data using Django's cache
199+ framework. Works with any cache backend (Memcached, Redis, database,
200+ file-based, etc.). See ``CACHE_BACKEND `` and ``CACHE_KEY_PREFIX `` below
201+ for configuration options.
202+
203+ The ``DatabaseStore `` and ``CacheStore `` both provide persistence across
204+ server restarts and automatically clean up old entries based on the
205+ ``RESULTS_CACHE_SIZE `` setting.
206+
207+ Note: When using ``DatabaseStore ``, migrations are required for
200208 the ``debug_toolbar `` app:
201209
202210 .. code-block :: bash
203211
204212 python manage.py migrate debug_toolbar
205213
206- For the ``DatabaseStore `` to work properly, you need to run migrations for the
207- ``debug_toolbar `` app. The migrations create the necessary database table to store
208- toolbar data.
214+ The toolbar's own cache and SQL operations are automatically hidden from
215+ the cache and SQL panels when using ``CacheStore ``, so you won't see the
216+ toolbar's internal bookkeeping in the collected metrics.
217+
218+ * ``CACHE_BACKEND ``
219+
220+ Default: ``"default" ``
221+
222+ The alias of the Django cache backend to use when ``TOOLBAR_STORE_CLASS ``
223+ is set to ``debug_toolbar.store.CacheStore ``. This should match one of
224+ the keys in your :setting: `CACHES ` setting.
225+
226+ Using a dedicated cache backend for the toolbar is recommended in
227+ production-like environments to avoid evicting application cache entries:
228+
229+ .. code-block :: python
230+
231+ CACHES = {
232+ " default" : {
233+ " BACKEND" : " django.core.cache.backends.redis.RedisCache" ,
234+ " LOCATION" : " redis://127.0.0.1:6379" ,
235+ },
236+ " debug-toolbar" : {
237+ " BACKEND" : " django.core.cache.backends.locmem.LocMemCache" ,
238+ },
239+ }
240+
241+ DEBUG_TOOLBAR_CONFIG = {
242+ " TOOLBAR_STORE_CLASS" : " debug_toolbar.store.CacheStore" ,
243+ " CACHE_BACKEND" : " debug-toolbar" ,
244+ }
245+
246+ * ``CACHE_KEY_PREFIX ``
247+
248+ Default: ``"djdt:" ``
249+
250+ A prefix applied to all cache keys used by the ``CacheStore ``. This
251+ prevents collisions with other cache entries when sharing a cache
252+ backend with the rest of your application.
209253
210254.. _TOOLBAR_LANGUAGE :
211255
@@ -418,12 +462,20 @@ Here's what a slightly customized toolbar configuration might look like::
418462 'SQL_WARNING_THRESHOLD': 100, # milliseconds
419463 }
420464
421- Here's an example of using a persistent store to keep debug data between server
465+ Here's an example of using the database store to keep debug data between server
422466restarts::
423467
424468 DEBUG_TOOLBAR_CONFIG = {
425- 'TOOLBAR_STORE_CLASS': 'debug_toolbar.store.DatabaseStore',
426- 'RESULTS_CACHE_SIZE': 100, # Store up to 100 requests
469+ "TOOLBAR_STORE_CLASS": "debug_toolbar.store.DatabaseStore",
470+ "RESULTS_CACHE_SIZE": 100, # Store up to 100 requests
471+ }
472+
473+ Here's an example of using the cache store, which provides persistence without
474+ requiring migrations::
475+
476+ DEBUG_TOOLBAR_CONFIG = {
477+ "TOOLBAR_STORE_CLASS": "debug_toolbar.store.CacheStore",
478+ "CACHE_BACKEND": "default", # Or a dedicated cache alias
427479 }
428480
429481Theming support
0 commit comments