Expand description
Experimental: Alpha Release
This crate is in early development. APIs are unstable and may change without notice. Not recommended for production use yet
Axum integration for HTTP cache tagging and validation.
This crate builds on the core http_cache_tags_core library to provide
middleware, extractors, and API handlers tailored for the Axum web framework.
It enables tag-based HTTP cache invalidation, cache metadata resolution, and response validation within Axum applications.
§Features
The features available here mirror those from the core crate and are propagated through this integration:
- Config File (
config_filefeature): Load cache config from TOML files. - ETag Support (
etagfeature): Generate and handle weak ETags. - Last-Modified Support (
last_modifiedfeature): Track resource modification timestamps. - Redis Integration (
redisfeature): Use Redis as a persistent backend for cache metadata.
§Components
This crate provides:
- Axum middleware to inject cache headers (
ETag,Last-Modified,Cache-Control). - Extractors for retrieving validated JSON payloads and cache metadata.
- API error types and controllers compatible with Axum.
§Example
use axum::{Router, routing::get};
use http_cache_tags_axum::prelude::*;
#[tokio::main]
async fn main() {
let config = CacheConfig::builder()
.invalidation_api_route("/_invalidate")
.add_route_mapping("/blog/*", vec!["blog"])
.build();
let runtime = CacheRuntime::builder().config(config).build();
let app = Router::new()
.route("/blog/{slug}", get(blog_handler));
runtime.attach_to(app);
// Serve app with hyper or axum server...
}
async fn blog_handler(meta: CacheMeta) -> String {
format!("Tags: {:?}, Last Modified: {:?}", meta.tags, meta.last_modified)
}§Integration
Use this crate alongside http_cache_tags_core to enable full cache
tagging support in Axum applications. It is recommended to use the
umbrella crate http_cache_tags
which bundles all framework integrations, including Actix and Axum.
Modules§
- api
- Axum integration for the cache invalidation API endpoint.
- core
- Core components re-exported from
http_cache_tags_core. - extractor
- Extractors for HTTP request handling in the cache tagging system.
- middleware
- Cache Validation Middleware
- prelude
- Prelude module for convenient imports.
- runtime
- Axum integration for HTTP cache tagging.