diff options
| author | Jeremy Dunck <jdunck@gmail.com> | 2007-06-25 19:33:37 +0000 |
|---|---|---|
| committer | Jeremy Dunck <jdunck@gmail.com> | 2007-06-25 19:33:37 +0000 |
| commit | fc779fe55aec84994e7e761c743716ba03484bcc (patch) | |
| tree | d139f5ce44133e630c7bb1b965baa3120ba23c99 /django/utils/functional.py | |
| parent | b0a56a9919d2304fa08b71373b53fdfb5ca72de9 (diff) | |
gis: Merged revisions 5491-5539 via svnmerge from
http://code.djangoproject.com/svn/django/trunk
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@5540 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/functional.py')
| -rw-r--r-- | django/utils/functional.py | 15 |
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 |
