Experimental: Alpha Release
This crate is in early development. APIs are unstable and may change without notice. Not recommended for production use yet.
http_cache_tags_axum
🔒 HTTP caching middleware and tooling for Axum applications with reverse proxies like NGINX or CDNs.
Designed for SSR sites (e.g. Leptos) backed by a headless CMS — enables route-based cache metadata headers and fine-grained invalidation.
Features
- Route pattern → cache key mapping (
globsupport) - Auto-set
Last-Modifiedheaders - Optional admin route for external invalidation
- Thread-safe runtime store with
DashMap - Middleware + Extractor support
- TOML config + programmatic builder
Getting Started
1. Install
# Cargo.toml
[]
= { = "<not available now>" }
2. Configure
cache.toml:
= "LastModified"
[]
= "your-shared-secret"
[]
= "/_invalidate"
[]
= ["posts"]
= ["products", "categories"]
Or build in code:
let config = builder
.add_route
.admin_path
.build;
// or from file
let config = load_from_file?;
3. Mount Middleware
use ;
use ;
let config = from_file?;
let runtime = config.build;
let app = runtime.attach_to;
CacheMeta Extractor
Access resolved keys and last-modified time from inside handlers:
async
Admin Invalidation API
If enabled in config:
POST /_invalidate
Authorization: Bearer your-shared-secret
Content-Type: application/json
{
"tags": ["posts", "categories"]
}
Clears the internal "dirty" flags and updates timestamps, triggering new Last-Modified values on next request.
Integration with NGINX / CDN
Add header caching rules in your reverse proxy:
location / {
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_cache my_cache;
proxy_cache_valid 200 1h;
proxy_cache_key $uri;
add_header Last-Modified $upstream_http_last_modified;
...
}
Your app only needs to send the right Last-Modified headers — the reverse proxy handles freshness.
Feature Flags
TODO
TODO / Contributions Welcome
- Redis adapter for shared cache
- CLI tool for manual invalidation
License
MIT