#26792: cache.get_or_set() calculates the default key value in case it is
already
cached
-------------------------------------+-------------------------------------
Reporter: dvska | Owner: nobody
Type: Bug | Status: new
Component: Core (Cache system) | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by dvska):
* 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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.fef55bd4411d697c31672c5c8a45625f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.