Opened 3 years ago

Closed 3 years ago

#32306 closed New feature (wontfix)

Add decorator django.utils.functional.cached_classproperty

Reported by: Boris Owned by: Boris Trubin
Component: Utilities Version: dev
Severity: Normal Keywords: cached classproperty
Cc: Claude Paroz, Simon Charette, Boris Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello,
I propose new decorator "cached_classproperty".
Django has a lot of methods for caching, like cached_page and cached_property.
Сaching improves response times.
It was useful for me. I needed to cache the class property because the calculation needed to be done on the value.
What do you think about it?
https://github.com/django/django/pull/13813

Attachments (1)

test.py (420 bytes ) - added by David Smith 3 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 by Mariusz Felisiak, 3 years ago

Cc: Claude Paroz Simon Charette added
Needs documentation: set
Needs tests: set
Triage Stage: UnreviewedAccepted

Tentatively accepted, but I'm not sure if it's feasible, see Simon's comment.

comment:2 by Boris, 3 years ago

Cc: Boris added
Version: 3.1master

comment:3 by Boris, 3 years ago

Owner: changed from nobody to Boris Trubin
Status: newassigned

by David Smith, 3 years ago

Attachment: test.py added

comment:4 by David Smith, 3 years ago

I fear I misunderstand the issue here, if so I am sorry. Can one of the existing Python caches be used here?

I've attached a small example where lru_cache is used stacked under the classproperty decorator.

class TestClass:
    @classproperty
    @lru_cache
    def test_property(self):
        time.sleep(2)

In my test case, I see the output as.

python test.py 
0:00:02.002166
0:00:00.000037

comment:5 by Mariusz Felisiak, 3 years ago

Needs documentation: unset
Needs tests: unset
Resolution: wontfix
Status: assignedclosed

Closing as "wontfix" since it looks unnecessary per discussion and David's comment. We can reopen after reaching a strong consensus on DevelopersMailingList. Thanks.

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