# Cache Invalidation

smoxy caches content at the edge to reduce load on your origin server. When content changes, you need to invalidate the cached version so visitors see the update. smoxy provides several methods to do this — from clearing a single URL to flushing entire tag groups.

All invalidation requests use the HTTP `BAN` method and require the **cache token** configured in your site's Basic Configuration.

{% hint style="info" %}
**Cloudflare users:** Cloudflare may block BAN/PURGE requests. See [Cloudflare Setup](https://docs.smoxy.eu/en/developer-guide/broken-reference) for the recommended workaround.
{% endhint %}

***

### Methods

#### Flush URL

Clears the cache for a specific URL.

```bash
curl -X BAN -H "secret: <token>" -H "url: /" https://www.example.com/
```

You can also pass the URL as the request target:

```bash
curl -X BAN -H "secret: <token>" https://www.example.com/products/my-product
```

#### Flush Tags

Clears all cached content tagged with one or more cache tags. Tags are set on your origin's responses using the `x-cache-tags` header (see Advanced Caching for tag configuration).

Flush a single tag:

```bash
curl -X BAN -H "secret: <token>" -H "tags: smartphones" https://www.example.com/
```

Flush multiple tags at once (comma-separated):

```bash
curl -X BAN -H "secret: <token>" -H "tags: smartphones,accessories" https://www.example.com/
```

**When to use tags:** Tags are the most efficient way to invalidate groups of related content. For example, if your shop tags product pages with their category name, you can flush all "Samsung" products with a single request instead of purging each URL individually.

**Common tagging strategies:**

| Strategy      | Tag Example                 | Use Case                         |
| ------------- | --------------------------- | -------------------------------- |
| By category   | `smartphones`, `laptops`    | New products added to a category |
| By brand      | `samsung`, `apple`          | Brand-wide price update          |
| By product ID | `product-123`               | Single product changed           |
| By page type  | `listing`, `detail`, `home` | Template or layout change        |

#### Flush File

Clears a specific cached file by its cache hash. This is useful when you know the exact cache entry to invalidate.

```bash
curl -X BAN -H "secret: <token>" -H "cache-file: 469640790ad5bda4d1cc6a19f6770214.html" https://www.example.com/
```

{% hint style="info" %}
**Tip:** The cache file hash is returned as a response header when Debug Headers are enabled.
{% endhint %}

#### Flush All

Clears the entire cache for the site. Use this as a last resort — it forces every request to be fetched fresh from your origin until the cache warms up again.

```bash
curl -X BAN -H "secret: <token>" -H "type: flushall" https://www.example.com/
```

***

### Choosing the Right Method

| Method         | Scope                  | Speed   | Origin Load             |
| -------------- | ---------------------- | ------- | ----------------------- |
| **Flush URL**  | Single URL             | Instant | Minimal                 |
| **Flush Tags** | Group of related pages | Instant | Moderate                |
| **Flush File** | Single cache entry     | Instant | Minimal                 |
| **Flush All**  | Entire site cache      | Instant | High (cache cold start) |

Start with the most targeted method. Use Flush URL for single pages, Flush Tags for groups, and Flush All only when necessary.

***

### Quick Actions

You can also clear cache without writing code using the Dashboard quick actions:

* **Clear Entire Cache** — same as Flush All
* **Clear Cache by URL** — same as Flush URL
* **Clear Cache by Tag** — same as Flush Tags
