Skip to content

Commit e74706b

Browse files
committed
docs: update cache status header section for legacy support [skip ci]
1 parent f2f3c84 commit e74706b

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
- **Cache Backends**: Built-in support for file system and memory caches, with the ability to implement custom backends (see [Cache Backends](#cache-backends)).
1818
- **Cache Maintenance API**: Optional REST endpoints for listing, retrieving, and deleting cache entries (see [Cache Maintenance API](#cache-maintenance-api-debug-only)).
1919
- **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)).
2121
- **Zero Dependencies**: No external dependencies, pure Go implementation.
2222

2323
![Made with VHS](https://vhs.charm.sh/vhs-3WOBtYTZzzXggFGYRudHTV.gif)
@@ -114,22 +114,30 @@ To use a custom [ServeMux](https://pkg.go.dev/net/http#ServeMux), pass `expapi.W
114114
| `WithSWRTimeout(time.Duration)` | Set the stale-while-revalidate timeout | `5 * time.Second` |
115115
| `WithLogger(*slog.Logger)` | Set a logger for debug output | `slog.New(slog.DiscardHandler)` |
116116

117-
## Cache Status Header
117+
## Cache Status Headers
118118

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:
120120

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.
128123

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
130135

131136
```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
133141
```
134142

135143
## Limitations

0 commit comments

Comments
 (0)