index: make sure to write cached subtrees if parent is invalidated

If e.g. the root tree is invalidated, we still want to write out
its children, since those may still have valid cache entries.