def _memorize(func):
  """Decorator to cache the given function's output.
  """

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