Compute the memcache_key only in get()
This will be used by the homepage caching later on.
Patch by: Sverre Rabbelier
--- a/app/soc/cache/base.py Sat Feb 21 00:43:56 2009 +0000
+++ b/app/soc/cache/base.py Sat Feb 21 00:45:19 2009 +0000
@@ -38,12 +38,15 @@
@wraps(func)
def wrapper(*args, **kwargs):
- result = get(*args, **kwargs)
+ result, key = get(*args, **kwargs)
if result:
return result
result = func(*args, **kwargs)
- put(result, *args, **kwargs)
+
+ if key:
+ put(result, key, *args, **kwargs)
+
return result
return wrapper
--- a/app/soc/cache/sidebar.py Sat Feb 21 00:43:56 2009 +0000
+++ b/app/soc/cache/sidebar.py Sat Feb 21 00:45:19 2009 +0000
@@ -41,20 +41,19 @@
"""
memcache_key = key(id)
- return memcache.get(memcache_key)
+ return memcache.get(memcache_key), memcache_key
-def put(sidebar, id, user):
+def put(sidebar, memcache_key, id, user):
"""Sets the sidebar for the specified user in the memcache.
Args:
sidebar: the sidebar to be cached
"""
- # Store sidebar for ten minutes since new programs might get added
+ # Store sidebar for just three minutes to force a refresh every so often
retention = 3*60
- memcache_key = key(id)
memcache.add(memcache_key, sidebar, retention)