Add a cache status header to the response

The header name is configurable, and defaults to `X-FastAPI-Cache`,
the value is either `HIT` or `MISS`.

Note that the header is not set at all when the cache is disabled.
This commit is contained in:
Martijn Pieters
2023-05-12 14:12:00 +01:00
committed by Martijn Pieters
parent 29426de95f
commit 915f3dd8f2
4 changed files with 28 additions and 3 deletions

View File

@@ -99,6 +99,7 @@ namespace | str, namespace to use to store certain cache items
coder | which coder to use, e.g. JsonCoder
key_builder | which key builder to use, default to builtin
injected_dependency_namespace | prefix for injected dependency keywords, defaults to `__fastapi_cache`.
cache_status_header | Name for the header on the response indicating if the request was served from cache; either `HIT` or `MISS`. Defaults to `X-FastAPI-Cache`.
You can also use `cache` as decorator like other cache tools to cache common function result.