def cachedmethod(f, cache={}):
 def _(*args, **kwargs):
  try:
   key = (f, tuple(args), frozenset(kwargs.items()))
  except:
   key = ''.join((str(_) for _ in (f, args, kwargs)))
  if (key not in cache):
   cache[key] = f(*args, **kwargs)
  return cache[key]
 return _

def cachedmethod ( f , cache = { } ) : def _ ( * args , ** kwargs ) : try : key = ( f , tuple ( args ) , frozenset ( kwargs . items ( ) ) ) except : key = '' . join ( ( str ( _ ) for _ in ( f , args , kwargs ) ) ) if ( key not in cache ) : cache [ key ] = f ( * args , ** kwargs ) return cache [ key ] return _
decorator to make a method use the cache .