Opened 8 years ago

Last modified 8 years ago

#26792 closed Cleanup/optimization

cache.get_or_set() calculates the default key value in case it is already cached — at Initial Version

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

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_which_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 (0)

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