def METHOD_NAME(cache_name):
    if not session:
        lckfile = _lock(cache_name)
        cache = shelve.open(cache_name, protocol=-1)
        # Store a reference to the lckfile to avoid to be
        # closed by gc
        cache.lckfile = lckfile
    else:
        if not hasattr(fn, '_memoize_session_cache'):
            fn._memoize_session_cache = {}
            memoize.session_functions.append(fn)
        cache = fn._memoize_session_cache
    return cache