kutil_http/cache/axum/
handlers.rs

1use super::{super::super::cache::*, headers::*};
2
3use ::axum::{extract::*, http::*, response::Response};
4
5/// Axum request handler that resets the cache and returns [no_content_handler].
6///
7/// Expects the cache to be available as state. See
8/// [Router::with_state](::axum::Router::with_state).
9pub async fn reset_cache_handler<CacheT, CacheKeyT>(State(cache): State<CacheT>) -> Response
10where
11    CacheT: Cache<CacheKeyT>,
12    CacheKeyT: CacheKey,
13{
14    tracing::info!("resetting cache");
15    cache.invalidate_all().await;
16    no_content_handler().await
17}
18
19/// Axum request handler with no content, no encoding, and no caching.
20pub async fn no_content_handler() -> Response {
21    StatusCode::NO_CONTENT.do_not_encode().do_not_cache()
22}