Opened 3 months ago
Last modified 3 months ago
#35770 assigned Cleanup/optimization
Improve recommendation for ignoring memcached-incompatible cache key warnings
Reported by: | Markus Amalthea Magnuson | Owned by: | Aditya Chaudhary |
---|---|---|---|
Component: | Core (Cache system) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Markus Amalthea Magnuson | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This section of the docs is a bit confusing to me:
https://docs.djangoproject.com/en/5.1/topics/cache/#cache-key-warnings
Why is the recommendation to add the code to a management module (and it's also not entirely clear what that means, especially for less experienced Python developers)? Wouldn't it be better to add it to the ready() method in one of your app configs?
I could not reliably get the first method to work, but the second one does, and is kind of what the ready() method is for?
I'd be happy to provide updated docs if this sounds like a reasonable change.
Change History (4)
comment:1 by , 3 months ago
Component: | Documentation → Core (Cache system) |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 3 months ago
I did exactly that, adding the code to __init_.py
inside of a management
folder (with no additional files) in an app that is in INSTALLED_APPS
. Tried two different apps, but the code just would not run. Not sure about the internals of detecting it in such a module specifically, but seems like there are better way to put code that needs to always run.
comment:3 by , 3 months ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:4 by , 3 months ago
So, Is this right for the changes. Should I proceed with it ?
If you are using a caching backend that accepts a wider range of keys (e.g., a custom backend or one of the non-Memcached built-in backends) and you prefer to suppress these warnings, you can do so with the following code. This code can be added to the ready() method of an AppConfig class in one of your INSTALLED_APPS, which is a more integrated and commonly used approach:
Hello Markus, thank you for taking the time to create this ticket. I agree that "management module" is a bit unclear. For me, that means adding the shown code inside the
__init__.py
file located at the toplevel of anymanagement
folder in any app.What did you try and what did not work?
Overall I think we can enhance the docs, at least making it more explicit what the "management module" is, so I'll accept on that basis.