Fixed #21351 -- Replaced memoize with Python's lru_cache.

Replaced the custom, untested memoize with a similar decorator from Python's
3.2 stdlib. Although some minor performance degradation (see ticket), it is
expected that in the long run lru_cache will outperform memoize once it is
implemented in C.

Thanks to EvilDMP for the report and Baptiste Mispelon for the idea of
replacing memoize with lru_cache.
This commit is contained in:
Bouke Haarsma 2013-11-01 21:15:41 +01:00 committed by Baptiste Mispelon
parent 6c5f5b9a41
commit 9b7455e918
13 changed files with 254 additions and 38 deletions

View file

@ -2,6 +2,7 @@ import copy
import operator
from functools import wraps
import sys
import warnings
from django.utils import six
from django.utils.six.moves import copyreg
@ -24,6 +25,10 @@ def memoize(func, cache, num_args):
Only the first num_args are considered when creating the key.
"""
warnings.warn(u"memoize wrapper is deprecated and will be removed in "
u"Django 1.9. Use django.utils.lru_cache instead.",
PendingDeprecationWarning, 2)
@wraps(func)
def wrapper(*args):
mem_args = args[:num_args]