[Django] #35276: Push cache backend checks down to backend classes

37 views
Skip to first unread message

Django

unread,
Mar 6, 2024, 5:46:42 PM3/6/24
to django-...@googlegroups.com
#35276: Push cache backend checks down to backend classes
------------------------------------------------+------------------------
Reporter: Adam Johnson | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (System checks) | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
Currently, the three system checks for caches are individual functions
[https://github.com/django/django/blob/main/django/core/checks/caches.py
in ​django.core.checks.caches]. But two of them relate only to
`FileBasedCache`, yet still run regardless of which backends are used.
This structure causes some issues:

1. `FileBasedCache` and its dependencies are imported even when not used.
2. Some waste in `check_cache_location_not_exposed()` when no
`FileBasedCache` is configured, which resolves some paths before checking
against caches.
3. The code structure is a bit messy with repeated loops and
`isinstance(cache, FileBasedCache)` conditions.

I propose restructuring these checks to live within the cache backend
classes in `django.core.cache.backends.*`, adopting the same pattern used
for model and field checks, admin checks, and staticfiles finders. (And
template backend checks, as I proposed in #35233.)

This would mean:

1. Adding `BaseCache.check()` which just does `return []` for now.
2. Pushing the existing two checks down to a new `FileBasedCache.check()`
method.
3. Dropping the existing code.
4. Checking tests cover the checks sufficiently and they pass with the new
structure.
5. Potentially adding a test to cover a custom cache backend with its own
check.
--
Ticket URL: <https://code.djangoproject.com/ticket/35276>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 6, 2024, 11:55:14 PM3/6/24
to django-...@googlegroups.com
#35276: Push cache backend checks down to backend classes
--------------------------------------+------------------------------------
Reporter: Adam Johnson | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (System checks) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Simon Charette):

* stage: Unreviewed => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/35276#comment:1>

Django

unread,
Mar 6, 2024, 11:56:10 PM3/6/24
to django-...@googlegroups.com
#35276: Push cache backend checks down to backend classes
--------------------------------------+------------------------------------
Reporter: Adam Johnson | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (System checks) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Mariusz Felisiak):

Agreed, we recently did the same thing with constraint check
(0fb104dda287431f5ab74532e45e8471e22b58c8).
--
Ticket URL: <https://code.djangoproject.com/ticket/35276#comment:2>

Django

unread,
Mar 7, 2024, 12:33:06 AM3/7/24
to django-...@googlegroups.com
#35276: Push cache backend checks down to backend classes
--------------------------------------+------------------------------------
Reporter: Adam Johnson | Owner: Almaz
Type: Cleanup/optimization | Status: assigned
Component: Core (System checks) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Almaz):

* owner: nobody => Almaz
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/35276#comment:3>

Django

unread,
Mar 14, 2024, 12:47:55 PM3/14/24
to django-...@googlegroups.com
#35276: Push cache backend checks down to backend classes
--------------------------------------+------------------------------------
Reporter: Adam Johnson | Owner: Almaz
Type: Cleanup/optimization | Status: assigned
Component: Core (System checks) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by bcail):

* cc: bcail (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/35276#comment:4>

Django

unread,
Mar 14, 2024, 12:48:29 PM3/14/24
to django-...@googlegroups.com
#35276: Push cache backend checks down to backend classes
--------------------------------------+------------------------------------
Reporter: Adam Johnson | Owner: Almaz
Type: Cleanup/optimization | Status: assigned
Component: Core (System checks) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by bcail):

@Almaz, are you still working on this ticket?
--
Ticket URL: <https://code.djangoproject.com/ticket/35276#comment:5>

Django

unread,
Mar 15, 2024, 3:12:42 AM3/15/24
to django-...@googlegroups.com
#35276: Push cache backend checks down to backend classes
--------------------------------------+------------------------------------
Reporter: Adam Johnson | Owner: Almaz
Type: Cleanup/optimization | Status: assigned
Component: Core (System checks) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Pro100-Almaz):

Yes, I am still working on this ticket
--
Ticket URL: <https://code.djangoproject.com/ticket/35276#comment:6>

Django

unread,
Mar 25, 2024, 3:59:38 AM3/25/24
to django-...@googlegroups.com
#35276: Push cache backend checks down to backend classes
--------------------------------------+------------------------------------
Reporter: Adam Johnson | Owner: Almaz
Type: Cleanup/optimization | Status: assigned
Component: Core (System checks) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 0 => 1
* needs_better_patch: 0 => 1
* needs_docs: 0 => 1
* needs_tests: 0 => 1

Comment:

[https://github.com/django/django/pull/18008 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/35276#comment:7>

Django

unread,
Dec 3, 2024, 8:22:27 AM12/3/24
to django-...@googlegroups.com
#35276: Push cache backend checks down to backend classes
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner:
Type: | tainarapalmeira
Cleanup/optimization | Status: assigned
Component: Core (System | Version: dev
checks) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by tainarapalmeira):

* owner: Almaz => tainarapalmeira

--
Ticket URL: <https://code.djangoproject.com/ticket/35276#comment:8>

Django

unread,
Apr 26, 2025, 11:47:33 AM4/26/25
to django-...@googlegroups.com
#35276: Push cache backend checks down to backend classes
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Tim
Type: | McCurrach
Cleanup/optimization | Status: assigned
Component: Core (System | Version: dev
checks) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim McCurrach):

* owner: tainarapalmeira => Tim McCurrach

Comment:

The existing PR appears to be stale, so I'll give this one another go :)
--
Ticket URL: <https://code.djangoproject.com/ticket/35276#comment:9>

Django

unread,
Sep 16, 2025, 3:05:35 PM9/16/25
to django-...@googlegroups.com
#35276: Push cache backend checks down to backend classes
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Tim
Type: | McCurrach
Cleanup/optimization | Status: assigned
Component: Core (System | Version: dev
checks) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_tests: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/35276#comment:10>
Reply all
Reply to author
Forward
0 new messages