def cache_decorator(func):
    """apply caching to the return value of a function."""

    name = '_cached_' + func.__name__

    def do_with_cache(self, *args, **kwargs):
        try:
            return getattr(self, name)
        except __HOLE__:
            value = func(self, *args, **kwargs)
            setattr(self, name, value)
            return value
    return do_with_cache
dataset/ETHPy150Open ralfonso/theory/theory/model/mpdutil.py/cache_decorator