#NEWLINE# def get( cls , id , using_db = None ) : #NEWLINE# #INDENT# if ( type ( id ) == ValuesListQuerySet ) : #NEWLINE# #INDENT# id = list ( id ) #NEWLINE# #UNINDENT# if hasattr ( id , '__iter__' ) : #NEWLINE# #INDENT# _pcresult = [ ] #NEWLINE# for i in id : #NEWLINE# #INDENT# pcr = _process_cache . get ( _cache_key ( cls , i ) ) #NEWLINE# if ( l is not None ) : #NEWLINE# #INDENT# _pcresult . append ( pcr ) #NEWLINE# #UNINDENT# #UNINDENT# if ( len ( _pcresult ) == len ( id ) ) : #NEWLINE# #INDENT# return _pcresult #NEWLINE# #UNINDENT# _mcresult = cache . get_many ( [ _cache_key ( cls , i ) for i in id ] ) #NEWLINE# if ( len ( _mcresult ) == len ( id ) ) : #NEWLINE# #INDENT# mc_result = map ( ( lambda t : _mcresult [ t ] ) , [ _cache_key ( cls , l ) for l in id ] ) #NEWLINE# for mc in mc_result : #NEWLINE# #INDENT# _process_cache [ _cache_key ( mc ) ] = mc #NEWLINE# #UNINDENT# return mc_result #NEWLINE# #UNINDENT# _id_diffs = set ( id ) . difference ( [ _mcresult [ l ] . id for l in _mcresult ] ) #NEWLINE# _fetch = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# manager = cls . objects #NEWLINE# if ( using_db is not None ) : #NEWLINE# #INDENT# manager = manager . using ( using_db ) #NEWLINE# #UNINDENT# _db_results = list ( manager . filter ( id__in = _id_diffs ) ) #NEWLINE# for l in _id_diffs : #NEWLINE# #INDENT# for fi in _db_results : #NEWLINE# #INDENT# if ( fi . id == l ) : #NEWLINE# #INDENT# _fetch [ _cache_key ( cls , l ) ] = fi #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for _i in _fetch : #NEWLINE# #INDENT# put ( _fetch [ _i ] ) #NEWLINE# #UNINDENT# _fetch . update ( dict ( zip ( _mcresult , [ _mcresult [ l ] for l in _mcresult ] ) ) ) #NEWLINE# results = [ ] #NEWLINE# for l in id : #NEWLINE# #INDENT# if _fetch . has_key ( _cache_key ( cls , l ) ) : #NEWLINE# #INDENT# results . append ( _fetch [ _cache_key ( cls , l ) ] ) #NEWLINE# #UNINDENT# #UNINDENT# return results #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# _obj = None #NEWLINE# try : #NEWLINE# #INDENT# _obj = _process_cache . get ( _cache_key ( cls , id ) ) #NEWLINE# if ( _obj is None ) : #NEWLINE# #INDENT# _obj = cache . get ( _cache_key ( cls , id ) ) #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# if ( _obj is None ) : #NEWLINE# #INDENT# _obj = cls . objects . get ( id = id ) #NEWLINE# put ( _obj ) #NEWLINE# #UNINDENT# return _obj