Opened 3 years ago

Last modified 9 months ago

#33604 assigned New feature

Allow `CacheMiddleware.key_prefix` to be a callable — at Initial Version

Reported by: Alexandru Mărășteanu Owned by: nobody
Component: Core (Cache system) Version: dev
Severity: Normal Keywords:
Cc: Tobias Kunze Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no
Pull Requests:18254 build:success, 15553 unmerged

Description

As discussed in https://groups.google.com/g/django-developers/c/UbD1DkV1uPo and https://code.djangoproject.com/ticket/11269 it would be useful to be able to specify a callable which would allow for more dynamic caching. In my case, I need to cache differently depending on whether the user is authenticated or not. Another scenario is to cache certain pages depending on some timestamp. Other uses cases were mentioned in the linked pages.

There exists https://github.com/peterbe/django-fancy-cache but I was able to address this by extending the built-in middleware so I really don't see an argument for a 3rd party package.

I'll try to open a PR for this.

According to the ticket's flags, the next step(s) to move this issue forward are:

  • To add tests to the patch, then uncheck the "Needs tests" flag on the ticket.
  • To write documentation for the patch, then uncheck "Needs documentation" on the ticket.
  • To improve the patch as described in the pull request review comments or on this ticket, then uncheck "Patch needs improvement".
  • If creating a new pull request, include a link to the pull request in the ticket comment when making that update. The usual format is: [https://github.com/django/django/pull/#### PR].

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top