import functools


def _generate_key(*args, **kwargs):
    return (args, frozenset(sorted(kwargs.items())))


def memoize(fun):
    """A simple memoize decorator for functions supporting (hashable)
    positional arguments.
    It also provides a cache_clear() function for clearing the cache: