code: def memoize_methodcalls(func, pickle=False, dumps=pickle.dumps):
      '''Cache the results of the function for each input it gets called with.
      '''
      cache = func._memoize_cache = {}
      @functools.wraps(func)
      def memoizer(self, *args, **kwargs):
          if pickle:
              key = dumps((args, kwargs))
          else:
              key = args
          if key not in cache:
              cache[key] = func(self, *args, **kwargs)
          return cache[key]
      return memoizef memoize_methodcalls(func, pickle=False, dumps=pickle.dumps):
      '''Cache the results of the function for each input it gets called with.
      '''
      cache = func._memoize_cache = {}
      @functools.wraps(func)
      def memoizer(self, *args, **kwargs):
          if pickle:
              key = dumps((args, kwargs))
          else:
              key = args
          if key not in cache:
              cache[key] = func(self, *args, **kwargs)
          return cache[key]
      return memoizer
docs: Cache the results of the function for each input it gets called with.