---
title: "content.cache"
description: "The storage backing the instance, holding parsed bodies and the index."
canonical_url: "https://content.comark.dev/reference/content/cache"
---
# content.cache

> The storage backing the instance, holding parsed bodies and the index.

## `content.cache`

The resolved [`Cache`](https://content.comark.dev/reference/types/content#cache) backing the instance. It is storage and nothing more: reading and writing content is the instance's job, so producing data lives on [`manifest()`](https://content.comark.dev/reference/content/manifest), [`snapshot()`](https://content.comark.dev/reference/content/snapshot) and [`refresh()`](https://content.comark.dev/reference/content/refresh).

| Method       | Signature                                  | Description                                                                                                                                                                                                    |
| ------------ | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `get`        | `(key: string) => Promise<T \| null>`      | Read a cached value by `<name>:<path>` key. Under `swr`, an expired entry is returned while it revalidates.                                                                                                    |
| `set`        | `(key: string, value: T) => Promise<void>` | Write a value into the cache.                                                                                                                                                                                  |
| `keys`       | `() => Promise<string[]>`                  | List the instance's content keys. Derived from the index, so it works on drivers without key enumeration.                                                                                                      |
| `clear`      | `() => Promise<void>`                      | Remove every entry this instance stores (index, bodies, raw bodies, artifacts). Other instances and refs on the driver are untouched. Used by [`clean()`](https://content.comark.dev/reference/content/clean). |
| `invalidate` | `(key: string) => Promise<void>`           | Remove one entry so the next read re-parses it.                                                                                                                                                                |
| `expire`     | `(key: string) => Promise<void>`           | Mark one entry stale, so `swr` serves it once more while refreshing.                                                                                                                                           |

## What lives in it

| Key                                             | Holds                                                                                                                                        |
| ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `<name>:<path-in-source>`                       | A fully parsed [`ContentFile`](https://content.comark.dev/reference/types/content#contentfiletdata-tmeta).                                   |
| `<name>:__raw__:<path-in-source>`               | The raw body of an [expensive-read source](https://content.comark.dev/sources/github), kept between a partial init and the first full parse. |
| `manifest`                                      | The persisted index, restored on a cold start.                                                                                               |
| `manifest-artifact`, `snapshot-artifact-<name>` | The checksummed HTTP artifacts, produced once per content change.                                                                            |

These are the keys `content.cache` methods take. Stored keys carry the instance name in front (`docs:manifest`) and, on a `withRef()` instance, a `ref:` namespace, so instances sharing one driver never collide.

## Usage

```ts [usage.ts]
// Drop one document so the next read re-parses it.
await content.cache.invalidate('default:posts/hello.md')

// Mark it stale instead: the next read still serves it, then refreshes.
await content.cache.expire('default:posts/hello.md')
```

See [caching](https://content.comark.dev/advanced/caching) for the driver, TTL, and stale-while-revalidate options.

::note
Passing `cache: false` swaps in a driver that stores nothing. Reads always reach the source, and the methods above keep working — `keys()` still answers from the index.
::


## Sitemap

See the full [sitemap](https://content.comark.dev/sitemap.md) for all pages.
