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
--
Ticket URL: <https://code.djangoproject.com/ticket/26792>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old 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
New 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_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
--
--
Ticket URL: <https://code.djangoproject.com/ticket/26792#comment:1>
* cc: d.v.selitsky@… (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/26792#comment:2>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/26792#comment:3>
* type: Bug => Cleanup/optimization
--
Ticket URL: <https://code.djangoproject.com/ticket/26792#comment:4>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"82be474efa81e5f2e127d711045a2ec06b206a8e" 82be474]:
{{{
#!CommitTicketReference repository=""
revision="82be474efa81e5f2e127d711045a2ec06b206a8e"
Fixed #26792 -- Allowed None for the value of cache.get_or_set().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26792#comment:5>