summaryrefslogtreecommitdiff
path: root/django/utils/functional.py
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-06-25 12:47:19 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-06-25 12:47:19 +0000
commit0ced8b0bb211fca38669293b15316930e0d648fd (patch)
treea6f4733859aed03765c396f843770b503c36ec90 /django/utils/functional.py
parentf4387422f0a556fb2469500fb9d408306bead02c (diff)
unicode: Merged from trunk up to [5530]. Oracle backend has not been ported to
support unicode yet. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5531 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/functional.py')
-rw-r--r--django/utils/functional.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/django/utils/functional.py b/django/utils/functional.py
index 574f433fd5..656f3406c4 100644
--- a/django/utils/functional.py
+++ b/django/utils/functional.py
@@ -3,6 +3,21 @@ def curry(_curried_func, *args, **kwargs):
return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
return _curried
+def memoize(func, cache):
+ """
+ Wrap a function so that results for any argument tuple are stored in
+ 'cache'. Note that the args to the function must be usable as dictionary
+ keys.
+ """
+ def wrapper(*args):
+ if args in cache:
+ return cache[args]
+
+ result = func(*args)
+ cache[args] = result
+ return result
+ return wrapper
+
class Promise(object):
"""
This is just a base class for the proxy class created in