summaryrefslogtreecommitdiff
path: root/django/utils/functional.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-07-01 01:17:51 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-07-01 01:17:51 +0000
commit6f4e933fcc78da11ec43214efd3472192030eced (patch)
treed92140118d3afa00bcd909f475dd1a694c15c08f /django/utils/functional.py
parent7a981380def046f753ff70a7c25efcd781ff6ac6 (diff)
newforms-admin: Merged to [5571]
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@5572 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 0c31c1f375..a57546ad2d 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:
"""
This is just a base class for the proxy class created in