def copy_cache(records, env):
 (todo, done) = (set(records), set())
 while todo:
  record = todo.pop()
  if (record not in done):
   done.add(record)
   target = record.with_env(env)
   for name in record._cache:
    field = record._fields[name]
    value = record[name]
    if isinstance(value, BaseModel):
     todo.update(value)
    target._cache[name] = field.convert_to_cache(value, target, validate=False)

def copy_cache ( records , env ) : ( todo , done ) = ( set ( records ) , set ( ) ) while todo : record = todo . pop ( ) if ( record not in done ) : done . add ( record ) target = record . with_env ( env ) for name in record . _cache : field = record . _fields [ name ] value = record [ name ] if isinstance ( value , BaseModel ) : todo . update ( value ) target . _cache [ name ] = field . convert_to_cache ( value , target , validate = False )
recursively copy the cache of records to the environment env .