To mitigate the performance issues of database queries, you can use the Django cached_db session back end, which utilizes both your database and caching infrastructure to perform write-through caching and efficient retrieval.
Enable this hybrid setting by configuring both your database and cache, as discussed previously. Then, set the following value:
SESSION_ENGINE = "django.contrib.sessions.backends.cached_db"