def add_to_cache(obj, name, val):
    """Add a result to the cache of an object."""
    if not hasattr(obj, '_memoize_cache'):
        obj._memoize_cache = dict()
    obj._memoize_cache[name] = val
    return obj
