Caching
Without a cache, every content.get() re-parses its document from the source. The cache stores parsed document bodies and the manifest index so repeated reads and cold starts stay cheap. It's on by default (in-memory) and fully optional.
get() for a path parses and stores it. Later reads return the stored copy until it's invalidated or expires.Options
Configure the cache with a CacheOptions object on comarkContent, or pass cache: false to disable it:
interface CacheOptions {
driver?: Driver
ttl?: number
strategy?: 'swr' | 'none'
loadManifest?: () => Promise<CacheArtifact | null>
loadSnapshot?: (source: string) => Promise<CacheArtifact | null>
}swr strategy, and no TTL) need no setup.| Option | Type | Default | Description |
|---|---|---|---|
driver | Driver | in-memory | unstorage driver backing the cache. |
ttl | number | undefined | Milliseconds before an entry is stale. Omit to never expire. |
strategy | 'swr' | 'none' | 'swr' | How a stale entry is served. |
loadManifest() | () => Promise<CacheArtifact> | undefined | Hydrate the manifest from a manifest artifact. |
loadSnapshot() | (source) => Promise<CacheArtifact> | undefined | Hydrate a source's bodies from a snapshot. |
driver
Any unstorage driver. In-memory by default (per instance); swap for Redis, a Vercel Runtime Cache, or similar to share the cache across instances.
ttl
Milliseconds before a cached entry is considered stale. Omit it (the default) and entries never expire. What happens once stale is set by strategy.
strategy
swr (default) serves a stale entry immediately and re-reads the source in the background, so fresh content lands on the next read. none skips the background refresh: a stale entry is treated as a miss and re-read on the next get().
loadManifest()
Hydrate the manifest from a pre-built manifest artifact on content.init(), so a cold instance starts warm. See Artifacts & hydration.
loadSnapshot()
Hydrate a source's bodies from a snapshot the first time it's read. See Artifacts & hydration.