"""
Memo decorators for globals - memoized values survive for as long as the
process lives.

Stores values in a module-level variable.
"""

from plone.memoize import volatile

_memos = {}

def memoize(fun):
    def get_key(fun, *args, **kwargs):
        return hash((args, frozenset(kwargs.items()),))
    def get_cache(fun, *args, **kwargs):
        return _memos
    return volatile.cache(get_key, get_cache)(fun)

__all__ = (memoize,)
