Skip to content

Backlink cache

Obsidian resolves backlinks with the undocumented app.metadataCache.getBacklinksForFile() function. Advanced Metadata Cache keeps a live index of every link in the vault and answers that call from the index, so it stays fast even when the vault grows to thousands of notes.

This vault has a small web of notes that all point at Central topic:

The button below asks the cache for the backlinks of Central topic and lists the notes that link to it. With the plugin enabled, the answer comes straight from the cache. It also uses the path-string overload the plugin adds - getBacklinksForFile('Topics/Central topic.md') - since the built-in version only accepts a TFile.

Button: Show cached backlinks for Central topic
import { Notice } from 'obsidian';
const dict = app.metadataCache.getBacklinksForFile('Topics/Central topic.md');
const paths = dict.keys();
new Notice(`Advanced Metadata Cache served ${paths.length.toString()} backlink(s):\n${paths.join('\n')}`);

Open the core Backlinks pane on Central topic and you will see the same list - Advanced Metadata Cache is what keeps that pane fast in a large vault.

Button: Open "Central topic
await require('/demoSetup.ts').showCentralTopicBacklinks(app);

Manual equivalent: open that note and run Backlinks: Show backlinks.