def cached_resource(cache_attribute):

    def decorator_factory(method_to_cache):

        def decorator(self, *args, **kwargs):
            method_name = method_to_cache.__name__
cache = getattr(self, cache_attribute)
try:
    return cache[method_name]
except KeyError:
    result = cache[method_name] = method_to_cache(self, *args, **kwargs)
return result
return decorator
return decorator_factory


class Profile(BeautifulSoup):

    def __init__(self, page_source):
        super().__init__(page_source)
self._cache = {}

@cached_resource('_cache')
def username(self):
    return self.title.split(':')[0]
Is it okay for decorators to access private members of a class?