Skip to content

Commit 8d1c975

Browse files
committed
Update docs and add to changes
1 parent f3c6e99 commit 8d1c975

3 files changed

Lines changed: 77 additions & 16 deletions

File tree

docs/architecture.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ the store ID. This is so that the toolbar can load the collected metrics
6868
for that particular request.
6969

7070
The history panel allows a user to view the metrics for any request since
71-
the application was started. The toolbar maintains its state entirely in
72-
memory for the process running ``runserver``. If the application is
73-
restarted the toolbar will lose its state.
71+
the application was started. By default, the toolbar maintains its state
72+
entirely in memory (``MemoryStore``) for the process running ``runserver``.
73+
If the application is restarted the toolbar will lose its state. To persist
74+
data across restarts, configure ``TOOLBAR_STORE_CLASS`` to use
75+
``DatabaseStore`` or ``CacheStore``. See the
76+
:ref:`TOOLBAR_STORE_CLASS <TOOLBAR_STORE_CLASS>` configuration option for details.
7477

7578
Problematic Parts
7679
-----------------

docs/changes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ Pending
1616
rather than on instantiation.
1717
* Highlighted the documentation about disabling the browser's caching to
1818
ensure the latest static assets are used.
19+
* Added ``debug_toolbar.store.CacheStore`` for storing toolbar data using
20+
Django's cache framework. This provides persistence without requiring
21+
database migrations, and works with any cache backend (Memcached, Redis,
22+
database, file-based, etc.).
23+
* Added ``CACHE_BACKEND`` and ``CACHE_KEY_PREFIX`` settings to configure the
24+
``CacheStore``.
1925

2026
6.2.0 (2026-01-20)
2127
------------------

docs/configuration.rst

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
422466
restarts::
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

429481
Theming support

0 commit comments

Comments
 (0)