def memoize(func):
    cache = {}

    @functools.wraps(func)
    def wrapped(*args):
        key = tuple(args)
        if key in cache:
            return cache[key]
        result = func(*args)
        len_cache = len(cache)
        if len_cache > MEMOIZE_KEY_LIMIT:
            cache_keys = cache.keys()
            for _unused in xrange(int(len_cache * MEMOIZE_FLUSH_RATE)):
                index_to_delete = random.randrange(0, len(cache_keys))
                key_to_delete = cache_keys.pop(index_to_delete)
                del cache[key_to_delete]
        cache[key] = result
        return result
    return wrapped
dataset/ETHPy150Open notmyname/slogging/slogging/access_log_delivery.py/memoize/original