@@ -436,6 +436,10 @@ def p_definition_type(p):
436436thrift_cache = {}
437437
438438
439+ def _get_cache_key (prefix , use_slots = False ):
440+ return ('%s:slotted' % prefix ) if use_slots else prefix
441+
442+
439443def parse (path , module_name = None , include_dirs = None , include_dir = None ,
440444 lexer = None , parser = None , enable_cache = True , use_slots = False ):
441445 """Parse a single thrift file to module object, e.g.::
@@ -471,7 +475,8 @@ def parse(path, module_name=None, include_dirs=None, include_dir=None,
471475
472476 global thrift_cache
473477
474- cache_key = module_name or os .path .normpath (path )
478+ cache_prefix = module_name or os .path .normpath (path )
479+ cache_key = _get_cache_key (cache_prefix , use_slots )
475480
476481 if enable_cache and cache_key in thrift_cache :
477482 return thrift_cache [cache_key ]
@@ -545,8 +550,10 @@ def parse_fp(source, module_name, lexer=None, parser=None, enable_cache=True, us
545550 raise ThriftParserError ('ThriftPy can only generate module with '
546551 '\' _thrift\' suffix' )
547552
553+ cache_key = _get_cache_key (module_name , use_slots )
554+
548555 if enable_cache and module_name in thrift_cache :
549- return thrift_cache [module_name ]
556+ return thrift_cache [cache_key ]
550557
551558 if not hasattr (source , 'read' ):
552559 raise ThriftParserError ('Except `source` to be a file-like object with'
@@ -569,7 +576,7 @@ def parse_fp(source, module_name, lexer=None, parser=None, enable_cache=True, us
569576 thrift_stack .pop ()
570577
571578 if enable_cache :
572- thrift_cache [module_name ] = thrift
579+ thrift_cache [cache_key ] = thrift
573580 return thrift
574581
575582
0 commit comments