Opened 4 years ago
Closed 4 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)
Change History (6)
comment:1 by , 4 years ago
Cc: | added |
---|---|
Needs documentation: | set |
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 4 years ago
Cc: | added |
---|---|
Version: | 3.1 → master |
comment:3 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
by , 4 years ago
comment:4 by , 4 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 , 4 years ago
Needs documentation: | unset |
---|---|
Needs tests: | unset |
Resolution: | → wontfix |
Status: | assigned → closed |
Closing as "wontfix" since it looks unnecessary per discussion and David's comment. We can reopen after reaching a strong consensus on DevelopersMailingList. Thanks.
Tentatively accepted, but I'm not sure if it's feasible, see Simon's comment.