def __call__(self, key_pattern, timeout=None):
def decorator(f):<EOL><INDENT>@functools.wraps(f)<EOL>def inner(*args, **kwargs):<EOL><INDENT>key = make_key(key_pattern, f, args, kwargs)<EOL>def x():<EOL><INDENT>return f(*args, **kwargs)<EOL><DEDENT>return self.call(x, key, timeout)<EOL><DEDENT>def clear(*args, **kwargs):<EOL><INDENT>key = make_key(key_pattern, f, args, kwargs)<EOL>self.delete(key)<EOL><DEDENT>inner.clear_cachelper_cache = clear<EOL>return inner<EOL><DEDENT>return decorator<EOL>
Use the cache object as a decorator factory.

        Args:
            key_pattern (str): the key pattern to use for generating
                               keys for caches of the decorated function
            timeout (int): the cache timeout for the key

        Returns:
            a decorator that cache return values of the decorated functions
            in keys generated based on the given key pattern
            and the calling args.

        Here's an example::

            @cache('key-name-for-{id}')
            def get_name(id):
                return 'name' + id