<s> """<STR_LIT>""" <EOL> usecache = False <EOL> _memcache_cache = { } <EOL> def memcache_decorator ( scope , instance = False ) : <EOL> """<STR_LIT>""" <EOL> def _memcache ( fun ) : <EOL> def _memcache_decorated ( * args , ** kwargs ) : <EOL> if not usecache : <EOL> return fun ( * args , ** kwargs ) <EOL> try : <EOL> if instance : <EOL> hash_key = hash ( ( args [ <NUM_LIT:1> : ] , frozenset ( sorted ( kwargs . items ( ) ) ) ) ) <EOL> else : <EOL> hash_key = hash ( ( args , frozenset ( sorted ( kwargs . items ( ) ) ) ) ) <EOL> except TypeError : <EOL> print repr ( ( args , kwargs ) ) <EOL> hash_key = None <EOL> if not hash_key : <EOL> return fun ( * args , ** kwargs ) <EOL> try : <EOL> ret = _memcache_cache . setdefault ( scope , { } ) [ hash_key ] <EOL> except KeyError : <EOL> ret = fun ( * args , ** kwargs ) <EOL> _memcache_cache [ scope ] [ hash_key ] = ret <EOL> return ret <EOL> return _memcache_decorated <EOL> return _memcache </s>
