Back to index

plone3  3.1.7
forever.py
Go to the documentation of this file.
00001 """
00002 Memo decorators for globals - memoized values survive for as long as the
00003 process lives.
00004 
00005 Stores values in a module-level variable.
00006 
00007 Pay attention that is module is not thread-safe, so use it with care.
00008 """
00009 
00010 from plone.memoize import volatile
00011 
00012 _memos = {}
00013 
00014 def memoize(fun):
00015     def get_key(fun, *args, **kwargs):
00016         return (args, frozenset(kwargs.items()),)
00017     def get_cache(fun, *args, **kwargs):
00018         return _memos
00019     return volatile.cache(get_key, get_cache)(fun)
00020 
00021 __all__ = (memoize,)