|
17 | 17 | - **Cache Backends**: Built-in support for file system and memory caches, with the ability to implement custom backends (see [Cache Backends](#cache-backends)). |
18 | 18 | - **Cache Maintenance API**: Optional REST endpoints for listing, retrieving, and deleting cache entries (see [Cache Maintenance API](#cache-maintenance-api-debug-only)). |
19 | 19 | - **Extensible**: Options for logging, transport and timeouts (see [Options](#options)). |
20 | | -- **Debuggable**: Adds a cache status header to every response (see [Cache Status Header](#cache-status-header)). |
| 20 | +- **Debuggable**: Adds a cache status header to every response (see [Cache Status Headers](#cache-status-headers)). |
21 | 21 | - **Zero Dependencies**: No external dependencies, pure Go implementation. |
22 | 22 |
|
23 | 23 |  |
@@ -114,22 +114,30 @@ To use a custom [ServeMux](https://pkg.go.dev/net/http#ServeMux), pass `expapi.W |
114 | 114 | | `WithSWRTimeout(time.Duration)` | Set the stale-while-revalidate timeout | `5 * time.Second` | |
115 | 115 | | `WithLogger(*slog.Logger)` | Set a logger for debug output | `slog.New(slog.DiscardHandler)` | |
116 | 116 |
|
117 | | -## Cache Status Header |
| 117 | +## Cache Status Headers |
118 | 118 |
|
119 | | -Every response includes a cache status header to indicate how the response was served. The header is named `X-Httpcache-Status` and can have the following values: |
| 119 | +This package sets a cache status header on every response: |
120 | 120 |
|
121 | | -| Status | Description | |
122 | | -| ------------- | ----------------------- | |
123 | | -| `HIT` | Served from cache | |
124 | | -| `MISS` | Fetched from origin | |
125 | | -| `STALE` | Served stale from cache | |
126 | | -| `REVALIDATED` | Revalidated with origin | |
127 | | -| `BYPASS` | Cache bypassed | |
| 121 | +- `X-Httpcache-Status`: The primary, detailed cache status header (always set). |
| 122 | +- `X-Cache-Status`: (Legacy) Provided for compatibility with [`gregjones/httpcache`](https://github.com/gregjones/httpcache). Only set for cache hits/stale/revalidated responses. |
128 | 123 |
|
129 | | -### Example |
| 124 | +### Header Value Mapping |
| 125 | + |
| 126 | +| X-Httpcache-Status | X-Cache-Status | Description | |
| 127 | +| ------------------ | -------------- | ---------------------------------- | |
| 128 | +| HIT | 1 | Served from cache | |
| 129 | +| STALE | 1 | Served from cache but stale | |
| 130 | +| REVALIDATED | 1 | Revalidated with origin | |
| 131 | +| MISS | *(not set)* | Served from origin | |
| 132 | +| BYPASS | *(not set)* | Bypassed cache, served from origin | |
| 133 | + |
| 134 | +### Example: Stale cache hit |
130 | 135 |
|
131 | 136 | ```http |
132 | | -X-Httpcache-Status: HIT |
| 137 | +HTTP/1.1 200 OK |
| 138 | +X-Httpcache-Status: STALE |
| 139 | +X-Cache-Status: 1 |
| 140 | +Content-Type: application/json |
133 | 141 | ``` |
134 | 142 |
|
135 | 143 | ## Limitations |
|
0 commit comments