Opened 8 years ago
Last modified 8 years ago
#28601 closed Cleanup/optimization
do not cache default callable return value of None in get_or_set — at Version 4
| Reported by: | Dan Tao | Owned by: | nobody |
|---|---|---|---|
| Component: | Core (Cache system) | Version: | 1.11 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
In 82be474 the change was made to allow None as a default value passed to
BaseCache.get_or_set. In case the default value of None is used, it is not
stored in the cache. This still left open the possibility that default could
be a callable that returns None, in which case it would be stored in the
cache.
# This scenario works as expected.
cache.get_or_set('foo', None) # None
cache.get_or_set('foo', 5) # 5
cache.get('foo') # 5
# This scenario seems wrong.
cache.get_or_set('bar', lambda: None) # None
cache.get_or_set('bar', 5) # None :(
cache.get('bar') # None :(
Change History (4)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
| Has patch: | set |
|---|
comment:3 by , 8 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Version: | 1.11 → master |
comment:4 by , 8 years ago
| Description: | modified (diff) |
|---|
Note:
See TracTickets
for help on using tickets.
I have already created a pull request for this issue, but I'm not sure how to officially associate it with this ticket so I'll just link to it here in a comment:
https://github.com/django/django/pull/9087