> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superwire.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent Caching

> Configure in-memory and Redis-backed agent execution caching.

Superwire can cache completed agent executions for repeat requests that use the same client-provided cache key. The executor only reads or writes cache entries when `options.cache_key` is present and `options.use_cache` is not `false`.

## Cache drivers

The executor supports two cache drivers:

| Driver      | Use case                                                                                                                      |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `in-memory` | Local development or a single executor process. Entries are lost when the process exits and are not shared across replicas.   |
| `redis`     | Shared cache storage for multiple executor processes or deployments that need cache persistence outside the executor process. |

The default cache driver is `in-memory`.

## Run with in-memory cache

```bash theme={"languages":{"custom":["/languages/wire.tmLanguage.json"]}}
superwire-executor --cache-driver in-memory --cache-ttl 1h
```

## Run with Redis cache

Use `--cache-driver redis` and provide the Redis host. Add `--redis-password` when your Redis instance requires authentication.

```bash theme={"languages":{"custom":["/languages/wire.tmLanguage.json"]}}
superwire-executor \
  --cache-driver redis \
  --redis-host 127.0.0.1:6379 \
  --redis-password "$REDIS_PASSWORD" \
  --redis-database 0 \
  --cache-ttl 30m
```

For Redis without a password, omit `--redis-password`.

```bash theme={"languages":{"custom":["/languages/wire.tmLanguage.json"]}}
superwire-executor --cache-driver redis --redis-host redis.internal:6379 --cache-ttl 30m
```

## Request cache keys

Cache entries are separated by `options.cache_key` in the `/execute` request body. Requests with the same cache key can reuse matching agent outputs. Requests with different cache keys do not share entries.

```bash theme={"languages":{"custom":["/languages/wire.tmLanguage.json"]}}
curl -X POST http://localhost:13703/execute \
  -H "content-type: application/json" \
  -d '{
    "workflow_source": "agent reply { instruction: \"Say hello\" output: string } output { result: agent.reply }",
    "options": {
      "cache_key": "tenant-1:conversation-42"
    }
  }'
```

When `options.cache_key` is omitted or empty, the executor bypasses cache reads and writes for that request.

## Rotate or invalidate a cache key

The simplest way to invalidate cached results is to send a new cache key. The playground does this automatically when the page loads, and its purge cache action regenerates the current workflow tab's cache key.

If you need to delete stored entries for a cache key, call `POST /cache/invalidate`.

```bash theme={"languages":{"custom":["/languages/wire.tmLanguage.json"]}}
curl -X POST http://localhost:13703/cache/invalidate \
  -H "content-type: application/json" \
  -d '{ "cache_key": "tenant-1:conversation-42" }'
```

The response includes the number of entries removed from the configured cache driver.

## Disable caching per request

Set `options.use_cache` to `false` to bypass reads and writes for a request.

```json theme={"languages":{"custom":["/languages/wire.tmLanguage.json"]}}
{
  "workflow_source_base64": "...",
  "options": {
    "cache_key": "tenant-1:conversation-42",
    "use_cache": false
  }
}
```
