Skip to content

Commit dd8470b

Browse files
committed
docs: Document per-principal cache namespacing and scope headers
When authentication is enabled, all cache layers are now automatically scoped per principal. Documents the new Results-Cache-Scope and Search-Results-Cache-Scope response headers, the Vary: Authorization behavior, and the breaking change requiring caching accelerator storage migration. Source: spiceai/spiceai#10702
1 parent e5fcb73 commit dd8470b

1 file changed

Lines changed: 34 additions & 6 deletions

File tree

website/docs/features/caching/index.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,34 @@ The encoding algorithm determines how cached results are compressed in memory, t
9090

9191
Use `zstd` when maximizing cache efficiency is important, especially for large queries that would otherwise quickly fill the cache. Use `none` for the lowest latency when memory is not constrained.
9292

93+
## Per-Principal Cache Isolation
94+
95+
When [authentication](../auth) is enabled, all cache layers (SQL results, search results, and caching-mode acceleration storage) are automatically scoped per principal. Each authenticated caller has an isolated cache namespace — one caller's cached output is never served to a different caller.
96+
97+
| Scenario | Cache namespace |
98+
| --- | --- |
99+
| Auth disabled or anonymous request | `public` — all callers share the cache |
100+
| Authenticated principal (e.g., API key) | Per-principal — isolated by a hash of the principal's identity |
101+
| Background / system tasks (e.g., SWR revalidation) | Inherits the originating principal's namespace |
102+
103+
There are no user-facing knobs to disable isolation. Scope follows authentication presence by construction.
104+
105+
:::warning[Breaking change for caching accelerator]
106+
The caching accelerator storage schema gains an internal `__spice_cache_namespace` column. Existing accelerator storage from earlier versions must be deleted (e.g., remove the `duckdb_file`, drop the backing table) before upgrading. The runtime errors with a clear message at startup if it encounters a non-extended schema.
107+
108+
The SQL results cache and search cache are in-memory and require no migration.
109+
:::
110+
93111
## Cached Responses
94112

95-
Responses from HTTP APIs include a header that indicates the cache status of the applicable cache:
113+
Responses from HTTP APIs include headers that indicate the cache status and scope:
96114

97-
| Cache | Header Key |
98-
| ---------------- | ----------------------------- |
99-
| `sql_results` | `Results-Cache-Status` |
100-
| `search_results` | `Search-Results-Cache-Status` |
115+
| Cache | Status Header | Scope Header |
116+
| ---------------- | ----------------------------- | ------------------------------- |
117+
| `sql_results` | `Results-Cache-Status` | `Results-Cache-Scope` |
118+
| `search_results` | `Search-Results-Cache-Status` | `Search-Results-Cache-Scope` |
101119

102-
The value of the header indicates the status of the cache:
120+
The status header indicates the cache status:
103121

104122
| Header value | Description |
105123
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
@@ -109,6 +127,14 @@ The value of the header indicates the status of the cache:
109127
| `STALE` | A stale cache entry was served while the cache is being revalidated in the background (when `stale_while_revalidate_ttl` is configured). |
110128
| _header not present_ | The cache did not apply to this query (e.g., when caching is disabled or querying a system table). |
111129

130+
The scope header indicates the cache namespace:
131+
132+
| Scope value | Description |
133+
| --- | --- |
134+
| `shared` | The cache entry is in the public namespace (auth disabled or anonymous). |
135+
| `user` | The cache entry is scoped to the authenticated principal. When the scope is `user`, the response also includes `Vary: Authorization`. |
136+
| `system` | The cache entry is in the system/background namespace. |
137+
112138
### Examples
113139

114140
#### Cached Response
@@ -118,6 +144,7 @@ $ curl -XPOST -i http://localhost:8090/v1/sql -d 'select * from taxi_trips limit
118144
HTTP/1.1 200 OK
119145
content-type: text/plain; charset=utf-8
120146
results-cache-status: HIT
147+
results-cache-scope: shared
121148
vary: origin, access-control-request-method, access-control-request-headers
122149
content-length: 416
123150
date: Thu, 13 Feb 2025 03:05:39 GMT
@@ -130,6 +157,7 @@ $ curl -XPOST -i http://localhost:8090/v1/sql -d 'select * from taxi_trips limit
130157
HTTP/1.1 200 OK
131158
content-type: text/plain; charset=utf-8
132159
results-cache-status: MISS
160+
results-cache-scope: shared
133161
vary: origin, access-control-request-method, access-control-request-headers
134162
content-length: 416
135163
date: Thu, 13 Feb 2025 03:13:19 GMT

0 commit comments

Comments
 (0)