Opened 8 years ago

Closed 8 years ago

#26792 closed Cleanup/optimization (fixed)

Allow None for the value of cache.get_or_set()

Reported by: Dmitry S..ky / skype: dvska-at-skype Owned by: nobody
Component: Core (Cache system) Version: 1.9
Severity: Normal Keywords:
Cc: d.v.selitsky@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Dmitry S..ky / skype: dvska-at-skype)

The check "if default is None" causing an unconditional calculation of the default value.

Behaviour before patch:

def heavy_routine_whose_result_to_be_cached():
    return todays_weather_forecast_calculated

...
cache.set('todays_weather_forecast', heavy_routine_whose_result_to_be_cached())
...
val = cache.get_or_set('todays_weather_forecast', heavy_routine_which_result_to_be_cached())  ## calculates 2nd time, which is unwanted behaviour

Proposed patch -> https://github.com/django/django/pull/6824

Change History (5)

comment:1 by Dmitry S..ky / skype: dvska-at-skype, 8 years ago

Description: modified (diff)

comment:2 by Dmitry S..ky / skype: dvska-at-skype, 8 years ago

Cc: d.v.selitsky@… added

comment:3 by Tim Graham, 8 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Tim Graham, 8 years ago

Summary: cache.get_or_set() calculates the default key value in case it is already cachedAllow None for the value of cache.get_or_set()
Type: BugCleanup/optimization

comment:5 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In 82be474:

Fixed #26792 -- Allowed None for the value of cache.get_or_set().

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