Skip to content

MetadataCache.on('changed') method

MetadataCache › on(‘changed’)

Official

Called when a file has been indexed, and its (updated) cache is now available.

Signature:

on(name: "changed", callback: (file: TFile, data: string, cache: CachedMetadata) => unknown, ctx?: unknown): EventRef

Parameters:

ParameterTypeDescription
name"changed"Should be 'changed'.
callback(file: TFile, data: string, cache: CachedMetadata) => unknownThe callback function.
ctx?unknownThe context passed as this to the callback function.

Returns: EventRefThe event reference.

Example:

app.metadataCache.on('changed', (file, data, cache) => {
console.log(file, data, cache);
});
```
Note: This is not called when a file is renamed for performance reasons.
You must hook the {@link obsidian#Vault .on | Vault.on(name: 'rename')} event for those.