Re: [Django] #33604: Allow CacheMiddleware.key_prefix to be a callable.

32 views
Skip to first unread message

Django

unread,
Mar 29, 2022, 1:14:41 AM3/29/22
to django-...@googlegroups.com
#33604: Allow CacheMiddleware.key_prefix to be a callable.
--------------------------------------+------------------------------------
Reporter: Alexandru Mărășteanu | Owner: nobody
Type: New feature | Status: new
Component: Core (Cache system) | 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 Mariusz Felisiak):

* cc: Tobias Kunze (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/33604#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 29, 2022, 1:18:14 AM3/29/22
to django-...@googlegroups.com
#33604: Allow CacheMiddleware.key_prefix to be a callable.
--------------------------------------+------------------------------------
Reporter: Alexandru Mărășteanu | Owner: nobody
Type: New feature | Status: new
Component: Core (Cache system) | 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 Alexandru Mărășteanu):

Replying to [comment:3 Mariusz Felisiak]:
> Tentatively accepted.

I started writing some tests the other evening so I'll try to open a PR
later today.

--
Ticket URL: <https://code.djangoproject.com/ticket/33604#comment:5>

Django

unread,
Mar 29, 2022, 5:48:06 AM3/29/22
to django-...@googlegroups.com
#33604: Allow CacheMiddleware.key_prefix to be a callable.
-------------------------------------+-------------------------------------
Reporter: Alexandru | Owner: Alexandru
Mărășteanu | Mărășteanu
Type: New feature | Status: assigned

Component: Core (Cache system) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Alexandru Mărășteanu):

* owner: nobody => Alexandru Mărășteanu
* status: new => assigned
* has_patch: 0 => 1


Comment:

I opened at PR at https://github.com/django/django/pull/15553
Unfortunately the tests stop running at some point due to an error which
I've yet to figure out.

--
Ticket URL: <https://code.djangoproject.com/ticket/33604#comment:6>

Django

unread,
Mar 29, 2022, 6:08:58 AM3/29/22
to django-...@googlegroups.com
#33604: Allow CacheMiddleware.key_prefix to be a callable.
-------------------------------------+-------------------------------------
Reporter: Alexandru | Owner: Alexandru
Mărășteanu | Mărășteanu
Type: New feature | Status: assigned
Component: Core (Cache system) | Version: dev
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 Mariusz Felisiak):

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


Comment:

Docs changes are missing. Also, many tests don't work.

--
Ticket URL: <https://code.djangoproject.com/ticket/33604#comment:7>

Django

unread,
Mar 30, 2022, 5:34:30 AM3/30/22
to django-...@googlegroups.com
#33604: Allow CacheMiddleware.key_prefix to be a callable.
-------------------------------------+-------------------------------------
Reporter: Alexandru | Owner: Alexandru
Mărășteanu | Mărășteanu
Type: New feature | Status: assigned
Component: Core (Cache system) | Version: dev
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
-------------------------------------+-------------------------------------

Comment (by Alexandru Mărășteanu):

Replying to [comment:7 Mariusz Felisiak]:


> Docs changes are missing. Also, many tests don't work.

I fixed the tests and updated the docs

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

Django

unread,
Apr 22, 2022, 4:55:55 AM4/22/22
to django-...@googlegroups.com
#33604: Allow CacheMiddleware.key_prefix to be a callable.
-------------------------------------+-------------------------------------
Reporter: Alexandru | Owner: Alexandru
Mărășteanu | Mărășteanu
Type: New feature | Status: assigned
Component: Core (Cache system) | 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):

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/33604#comment:9>

Django

unread,
Feb 14, 2023, 12:04:59 PM2/14/23
to django-...@googlegroups.com
#33604: Allow CacheMiddleware.key_prefix to be a callable.
-------------------------------------+-------------------------------------
Reporter: Alexandru | Owner: Alexandru
Mărășteanu | Mărășteanu
Type: New feature | Status: assigned
Component: Core (Cache system) | 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
-------------------------------------+-------------------------------------

Comment (by noneNote):

Replying to [comment:8 Alexandru Mărășteanu]:


> Replying to [comment:7 Mariusz Felisiak]:
> > Docs changes are missing. Also, many tests don't work.
>
> I fixed the tests and updated the docs

--
Ticket URL: <https://code.djangoproject.com/ticket/33604#comment:10>

Django

unread,
Jun 8, 2024, 10:18:30 AM6/8/24
to django-...@googlegroups.com
#33604: Allow CacheMiddleware.key_prefix to be a callable.
-------------------------------------+-------------------------------------
Reporter: Alexandru | Owner: Stefan
Mărășteanu | Farmbauer
Type: New feature | Status: assigned
Component: Core (Cache system) | 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 Stefan Farmbauer):

* owner: Alexandru Mărășteanu => Stefan Farmbauer

--
Ticket URL: <https://code.djangoproject.com/ticket/33604#comment:11>

Django

unread,
Jun 8, 2024, 10:21:03 AM6/8/24
to django-...@googlegroups.com
#33604: Allow CacheMiddleware.key_prefix to be a callable.
-------------------------------------+-------------------------------------
Reporter: Alexandru | Owner: Alexandru
Mărășteanu | Mărășteanu
Type: New feature | Status: assigned
Component: Core (Cache system) | 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 Stefan Farmbauer):

* owner: Stefan Farmbauer => Alexandru Mărășteanu

--
Ticket URL: <https://code.djangoproject.com/ticket/33604#comment:12>

Django

unread,
Jun 8, 2024, 11:11:10 AM6/8/24
to django-...@googlegroups.com
#33604: Allow CacheMiddleware.key_prefix to be a callable.
-------------------------------------+-------------------------------------
Reporter: Alexandru | Owner: Stefan
Mărășteanu | Farmbauer
Type: New feature | Status: assigned
Component: Core (Cache system) | 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 Stefan Farmbauer):

* owner: Alexandru Mărășteanu => Stefan Farmbauer


Old 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.

New 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.

(PR is 18254)[https://github.com/django/django/pull/18254]

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