Tags in newly created file not showing in file cache

When I create a file with my plugin, I’m inserting a string as the content data. This string contains hashtags. eg: contexts: #contexts/car projects: #projects/do-this.

However when I loop through all the tags in the vault, the tags are nowhere to be found.

Code to get all the tags:

const abstractFiles = app.vault.getAllLoadedFiles();

abstractFiles.forEach((file: TAbstractFile) => {
  if (!(file instanceof TFile)) return;

  const cache = window.app.metadataCache.getFileCache(file as TFile);
  if (!cache) return;

  const cachedTags = getAllTags(cache) || [];
  console.log('cached tags', cachedTags);
});

I was first creating the files using await this.app.vault.create(path, data);

I thought maybe I was creating files in such a way that the cache wasn’t being updated.

So I looked at the code for the Templater plugin and saw they were doing this:

const file: TFile = await app.fileManager.createNewMarkdownFile(
  folder as TFolder,
  name
);
await app.vault.modify(file, data);

But the issue is still happening. Is there some way to tell obsidian to parse the newly created file and build its cache with any tags in the file content?

Thanks!