File tree Expand file tree Collapse file tree 1 file changed +27
-3
lines changed
Expand file tree Collapse file tree 1 file changed +27
-3
lines changed Original file line number Diff line number Diff line change 2727
2828
2929def memoize_in_cache (cache_key , cache_timeout_seconds = None ):
30- """Cache the result of a no-args function."""
30+ """
31+ Caches the result of a no-args function. Further, a backup cache is
32+ maintained, updated as often as the primary but waits much longer to expire
33+ than the primary cache.
34+
35+ NOTE This should all go away once gondor gets schedule celery tasks that
36+ can be used to periodically populate the meetup.com event cache (thereby
37+ allowing visitor requests to avoid the hit).
38+ """
39+
40+ backup_cache_key = cache_key + '_backup'
41+ backup_cache_timeout_seconds = (cache_timeout_seconds * 100
42+ if cache_timeout_seconds else
43+ 60 * 60 * 24 )
44+
3145 def decorator (func ):
3246 @wraps (func )
3347 def decorated ():
3448 value = cache .get (cache_key )
3549 if not value :
36- value = func ()
37- cache .set (cache_key , value , cache_timeout_seconds )
50+ try :
51+ value = func ()
52+ cache .set (cache_key , value , cache_timeout_seconds )
53+ cache .set (backup_cache_key , value ,
54+ backup_cache_timeout_seconds )
55+ except :
56+ value = cache .get (backup_cache_key )
57+ if value :
58+ logging .exception ('Had to load backup value due to '
59+ 'exception' )
60+ else :
61+ raise
3862 return value
3963 return decorated
4064 return decorator
You can’t perform that action at this time.
0 commit comments