<s> import os <EOL> import imposm . config <EOL> from . tc import DeltaCoordsDB , CoordDB , NodeDB , WayDB , InsertedWayDB , RelationDB <EOL> class OSMCache ( object ) : <EOL> def __init__ ( self , path , prefix = '<STR_LIT>' , suffix = '<STR_LIT>' ) : <EOL> self . path = path <EOL> self . prefix = prefix <EOL> self . suffix = suffix <EOL> self . coords_fname = os . path . join ( path , prefix + '<STR_LIT>' + suffix ) <EOL> self . nodes_fname = os . path . join ( path , prefix + '<STR_LIT>' + suffix ) <EOL> self . ways_fname = os . path . join ( path , prefix + '<STR_LIT>' + suffix ) <EOL> self . inserted_ways_fname = os . path . join ( path , prefix + '<STR_LIT>' + suffix ) <EOL> self . relations_fname = os . path . join ( path , prefix + '<STR_LIT>' + suffix ) <EOL> self . caches = { } <EOL> def close_all ( self ) : <EOL> for mode_ , cache in self . caches . values ( ) : <EOL> cache . close ( ) <EOL> self . caches = { } <EOL> def coords_cache ( self , mode = '<STR_LIT:r>' , estimated_records = None ) : <EOL> if imposm . config . imposm_compact_coords_cache : <EOL> coords_db = DeltaCoordsDB <EOL> else : <EOL> coords_db = CoordDB <EOL> return self . _x_cache ( self . coords_fname , coords_db , mode , estimated_records ) <EOL> def nodes_cache ( self , mode = '<STR_LIT:r>' , estimated_records = None ) : <EOL> return self . _x_cache ( self . nodes_fname , NodeDB , mode , estimated_records ) <EOL> def ways_cache ( self , mode = '<STR_LIT:r>' , estimated_records = None ) : <EOL> return self . _x_cache ( self . ways_fname , WayDB , mode , estimated_records ) <EOL> def inserted_ways_cache ( self , mode = '<STR_LIT:r>' , estimated_records = None ) : <EOL> return self . _x_cache ( self . inserted_ways_fname , InsertedWayDB , mode , estimated_records ) <EOL> def remove_inserted_way_cache ( self ) : <EOL> if os . path . exists ( self . inserted_ways_fname ) : <EOL> os . unlink ( self . inserted_ways_fname ) <EOL> def relations_cache ( self , mode = '<STR_LIT:r>' , estimated_records = None ) : <EOL> return self . _x_cache ( self . relations_fname , RelationDB , mode , estimated_records ) <EOL> def _x_cache ( self , x , x_class , mode , estimated_records = None ) : <EOL> if x in self . caches : <EOL> current_mode , cache = self . caches [ x ] <EOL> if current_mode == mode : <EOL> return cache <EOL> else : <EOL> cache . close ( ) <EOL> cache = x_class ( x , mode , estimated_records = estimated_records ) <EOL> self . caches [ x ] = mode , cache <EOL> return cache </s>
