func (t *TreeMemoryCache) Flush() error {
	return t.underlyingStore.Update(func(tx TreeDatabaseTransaction) error {
		for _, dirtyNode := range t.dirty {
			err := tx.SetNode(&dirtyNode)
			if err != nil {
				return err
			}
		}

		for c := range t.toRemove {
			err := tx.DeleteNode(c)
			if err != nil {
				return err
			}
		}

		root := t.root

		if !root.IsEqual(&primitives.EmptyTree) {
			rootNode, err := tx.GetNode(root)
			if err != nil {
				return err
			}

			err = tx.SetRoot(rootNode)
			if err != nil {
				return err
			}
		}

		for k, v := range t.dirtyKV {
			err := tx.Set(k, v)
			if err != nil {
				return err
			}
		}

		return nil
	})
}
// Flush flushes the transaction to the underlying tree.
Flush flushes the transaction to the underlying tree.
// Flush flushes the transaction to the underlying tree .
func (t *TreeMemoryCache) Flush() error {
	return t.underlyingStore.Update(func(tx TreeDatabaseTransaction) error {
		for _, dirtyNode := range t.dirty {
			err := tx.SetNode(&dirtyNode)
			if err != nil {
				return err
			}
		}
		for c := range t.toRemove {
			err := tx.DeleteNode(c)
			if err != nil {
				return err
			}
		}
		root := t.root
		if !root.IsEqual(&primitives.EmptyTree) {
			rootNode, err := tx.GetNode(root)
			if err != nil {
				return err
			}
			err = tx.SetRoot(rootNode)
			if err != nil {
				return err
			}
		}
		for k, v := range t.dirtyKV {
			err := tx.Set(k, v)
			if err != nil {
				return err
			}
		}
		return nil
	})
}
func ( t * TreeMemoryCache ) Flush ( ) error { return t . underlyingStore . Update ( func ( tx TreeDatabaseTransaction ) error { for _ , dirtyNode := range t . dirty { err := tx . SetNode ( & dirtyNode ) if err != nil { return err } } for c := range t . toRemove { err := tx . DeleteNode ( c ) if err != nil { return err } } root := t . root if ! root . IsEqual ( & primitives . EmptyTree ) { rootNode , err := tx . GetNode ( root ) if err != nil { return err } err = tx . SetRoot ( rootNode ) if err != nil { return err } } for k , v := range t . dirtyKV { err := tx . Set ( k , v ) if err != nil { return err } } return nil } ) }
Flush flushes the transaction to the underlying tree.
Flush flushes the transaction to the underlying tree .