def _memorize(func):
def _wrapper(self, *args, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>if self.use_cache:<EOL><INDENT>cache = load_cache(self.cache_filename)<EOL>original_key = '<STR_LIT::>'.join([<EOL>self.__class__.__name__,<EOL>func.__name__,<EOL>'<STR_LIT:_>'.join([str(a) for a in args]),<EOL>'<STR_LIT:_>'.join([str(w) for w in kwargs.values()])])<EOL>cache_key = hashlib.md5(original_key.encode('<STR_LIT:utf-8>')).hexdigest()<EOL>cached_val = cache.get(cache_key)<EOL>if cached_val:<EOL><INDENT>return cached_val<EOL><DEDENT><DEDENT>val = func(self, *args, **kwargs)<EOL>if self.use_cache:<EOL><INDENT>cache.set(cache_key, val)<EOL><DEDENT>return val<EOL><DEDENT>return _wrapper<EOL>
Decorator to cache the given function's output.