getCacheSafe
Retrieves the cached metadata for a given file or path.
This is NOT a pure read: before it reads the cache, it calls saveNote, which saves any open editor view of the note that has unsaved changes. That save is why the cache matches what the user sees, and why a command that rewrites the note can use this safely without its rewrite being clobbered. It is also a write on the note. So do not call this from an automatic trigger (a vault or metadata event, a save or render patch, a layout hook) that only decides whether to act: a forced save one tick after another plugin has dispatched a change into the editor can leave Obsidian’s editor rendering stale state. A read-only probe on the note’s current text should use parseMetadata on that text instead. It needs no view, no cache and no save.
Import:
import { getCacheSafe } from '@mnaoumov/obsidian-lib/metadata-cache';Signature:
function getCacheSafe(app: App, fileOrPath: PathOrFile, options: ParseCacheOptions): Promise<CachedMetadataEx | null>Parameters:
| Parameter | Type | Description |
|---|---|---|
app |
App | The Obsidian app instance. |
fileOrPath |
PathOrFile | The file or path to retrieve the metadata for. |
options |
ParseCacheOptions | The parse options controlling which additional links to parse. |
Returns: Promise<CachedMetadataEx | null> — The cached metadata for the file, or null if it doesn’t exist.
Links to this page: