Opened 5 years ago

Last modified 5 years ago

#28601 closed Cleanup/optimization

do not cache default callable return value of None in get_or_set — at Initial Version

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

In [82be474 https://github.com/django/django/commit/82be474efa81e5f2e127d711045a2ec06b206a8e] 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 (0)

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