Store the cache alias on the cache backend instance
- Dominant language
- No language data
- Stars
- 188
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Description
### Code of Conduct
- [x] I agree to follow Django's Code of Conduct
### Feature Description
Store the alias used to fetch a cache backend instance on the instance itself.
```python
from django.core.cache import cache
print(cache.alias)
# "default"
```
Note: It may be beneficial to do this for all implementations of `BaseConnectionHandler`.
### Problem
The Django Debug Toolbar is having to do some extra patching (https://github.com/django-commons/django-debug-toolbar/pull/2219) to retain what alias is being used for which cache. While tolerable, it means the toolbar is having to reimplement more parts of Django, making it more brittle for future versions.
### Request or proposal
proposal
### Additional Details
It seems reasonable for a user to determine which alias was used when you have a cache backend instance. This may be useful in other contexts that I haven't encountered.
### Implementation Suggestions
- Update [`CacheHandler.create_connection`](https://github.com/django/django/blob/c4e07f94ebc1f9eaa3dae7b3dc6a2b9832182a10/django/core/cache/__init__.py#L43) to pass `alias` as `backend_cls(location, params, alias=alias)`
- Update [`django.core.cache.backends.base.BaseCache.__init__`](https://github.com/django/django/blob/c4e07f94ebc1f9eaa3dae7b3dc6a2b9832182a10/django/core/cache/backends/base.py#L61) to accept and store `alias`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.