#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. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107018e15f27f4b-c1de4b08-05ab-40cb-a663-2867cebc3cd9-000000%40eu-central-1.amazonses.com.