code: func (cache *Cache) Sync(st Writer) error {
  	if cache.readonly {
  		// Sync is (should be) a no-op for read-only - any modifications should have been caught in respective methods
  		return nil
  	}
  	cache.Lock()
  	defer cache.Unlock()
  	var addresses crypto.Addresses
  	for address := range cache.accounts {
  		addresses = append(addresses, address)
  	}
  
  	sort.Sort(addresses)
  	for _, address := range addresses {
  		accInfo := cache.accounts[address]
  		accInfo.RLock()
  		if accInfo.removed {
  			err := st.RemoveAccount(address)
  			if err != nil {
  				return err
  			}
  		} else if accInfo.updated {
  			// First update account in case it needs to be created
  			err := st.UpdateAccount(accInfo.account)
  			if err != nil {
  				return err
  			}
  			// Sort keys
  			var keys binary.Words256
  			for key := range accInfo.storage {
  				keys = append(keys, key)
  			}
  			sort.Sort(keys)
  			// Update account's storage
  			for _, key := range keys {
  				value := accInfo.storage[key]
  				err := st.SetStorage(address, key, value)
  				if err != nil {
  					return err
  				}
  			}
  
  		}
  		accInfo.RUnlock()
  	}
  	return nil
  }
docs: // Syncs changes to the backend in deterministic order. Sends storage updates before updating
  // the account they belong so that storage values can be taken account of in the update.