---
title: "content.clean()"
description: "Delete an instance's persisted data, then dispose it."
canonical_url: "https://content.comark.dev/reference/content/clean"
---
# content.clean()

> Delete an instance's persisted data, then dispose it.

## `content.clean(options?)`{lang="ts"}

Deletes everything the instance persisted, then [disposes](https://content.comark.dev/reference/content/dispose) it. Other instances and other refs sharing the same cache driver or database are left alone.

```ts [clean.ts]
// A preview branch was deleted: drop what its instance stored.
await content.withRef('feature/old-guide').clean()
```

### Parameters

- `options.force`: allow cleaning the default (ref-less) instance. Without it, `clean()` refuses, since that would delete the main data.

### Returns

`Promise<void>`{lang="ts"}

## What it deletes, in order

1. **The `clean` hook fires** with `{ ref, key }`, before anything is removed. Delete what you store outside the content cache for this instance here: a snapshot pushed by a custom loader, a rendered page cache keyed on the ref.
2. **Plugin `onClean` callbacks run**, in reverse setup order. The [`sqlQuery`](https://content.comark.dev/plugins/built-in/sql-query) plugin drops the instance's tables; [full-text search](https://content.comark.dev/plugins/built-in/full-text-search) deletes the instance's rows from the shared table.
3. **The cache namespace is cleared**: index, bodies, raw bodies, and HTTP artifacts. On a driver that can list keys, everything under the instance's prefix goes; on a key-less driver (Vercel Runtime Cache), the entries the index knows about go, which is everything but stray user-stored keys.
4. **`dispose()`** runs.

A failure partway leaves the instance usable and the cheapest thing left to redo. Calling `clean()` on a disposed instance throws.

## Notes

- A fresh instance at the same ref starts cold and rebuilds from the source or the build artifact.
- Pruning many stale refs at once is not built in. Keep the list of refs you created, and clean each.


## Sitemap

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