def memoize(ttl=None):
def decorator(obj):<EOL><INDENT>cache = obj.cache = {}<EOL>@functools.wraps(obj)<EOL>def memoizer(*args, **kwargs):<EOL><INDENT>now = datetime.now()<EOL>key = str(args) + str(kwargs)<EOL>if key not in cache:<EOL><INDENT>cache[key] = (obj(*args, **kwargs), now)<EOL><DEDENT>value, last_update = cache[key]<EOL>if ttl and (now - last_update) > ttl:<EOL><INDENT>cache[key] = (obj(*args, **kwargs), now)<EOL><DEDENT>return cache[key][<NUM_LIT:0>]<EOL><DEDENT>return memoizer<EOL><DEDENT>return decorator<EOL>
Cache the result of the function call with given args for until
        ttl (datetime.timedelta) expires.