Opened 9 years ago
Last modified 9 years ago
#26792 closed Cleanup/optimization
cache.get_or_set() calculates the default key value in case it is already cached — at Version 1
| 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 )
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
Note:
See TracTickets
for help on using tickets.