Example #1
0
 def cached_func(func, n):
     int_cache = getattr_(func, "int_cache", mk_int_cache) 
     if not (0 <= n < size):
         return func(n)
     if int_cache[n] is Empty:
         int_cache[n] = func(n)
     return int_cache[n]
Example #2
0
def cache(func, *args):
    cache_dict = getattr_(func, "cache_dict", dict) 
    # cache_dict is created at the first call
    if args in cache_dict:
        return cache_dict[args]
    else:
        result = func(*args)
        cache_dict[args] = result
        return result