import functools


def cache(fn):
    """Decorator to cache inputs to functions"""
    _cache = []
    _results = []

    @functools.wraps(fn)
    def func(*args):
        """
        :returns result of function if input was cached,
        else it calls fn and returns the result
        """
        if len(_cache) > 1000:
            _cache.clear()
            _results.clear()
        if args in _cache:
            return _results[_cache.index(args)]

        result = fn(*args)
        _cache.append(args)
        _results.append(result)

        return result

    return func