parameters: (cachefunc)
return_statement: return decorator
docstring: Decorator to wrap a class or instance method with a memoizing callable that
      saves results in a (possibly shared) cache.
docstring_summary: Decorator to wrap a class or instance method with a memoizing callable that
      saves results in a (possibly shared) cache.
docstring_tokens: Decorator to wrap a class or instance method with a memoizing callable that saves results in a ( possibly shared ) cache .
function: def cachedmethod(cachefunc):
      '''Decorator to wrap a class or instance method with a memoizing callable that
      saves results in a (possibly shared) cache.
      '''
      def decorator(method):
          def wrapper(self, *args, **kwargs):
              mapping = cachefunc(self)
              if mapping is None:
                  return method(self, *args, **kwargs)
              key = (method.__name__, args, tuple(sorted(kwargs.items())))
              try:
                  value = mapping[key]
                  return value
              except KeyError:
                  pass
              result = method(self, *args, **kwargs)
              mapping[key] = result
              return result
          return functools.update_wrapper(wrapper, method)
      return decorator
function_tokens: def cachedmethod ( cachefunc ) : def decorator ( method ) : def wrapper ( self , * args , * * kwargs ) : mapping = cachefunc ( self ) if mapping is None : return method ( self , * args , * * kwargs ) key = ( method . __name__ , args , tuple ( sorted ( kwargs . items ( ) ) ) ) try : value = mapping [ key ] return value except KeyError : pass result = method ( self , * args , * * kwargs ) mapping [ key ] = result return result return functools . update_wrapper ( wrapper , method ) return decorator