KO
|
EN
gitlite — search
Search
#python
#java
#python3
#arduino
#golang
#machine-learning
#rust
#html
#flask
#javascript
#seismology
#nodejs
axum-response-cache
★ 27
Open GitHub ↗
No description available.
Download README (.md)
Explore Similar Repositories
canny-edge-detection
:
Canny edge detector implemented in CUDA C/C++
llm-colab-application
:
[ 演講用 ] LLM AI 模型 Colab 應用
framos-jetson-drivers
:
No description available.
MambaByte
:
[CoLM 24] Official Repository of MambaByte: Token-free Selective State Space Model
postgres-context-server
:
A Model Context Protocol server for Postgres
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
axum-response-cache
?
Download (.md)
This library provides Axum middleware that caches HTTP responses to the incoming requests based on their HTTP method and path. The main struct is [`CacheLayer`](https://docs.rs/axum-response-cache/latest/axum_response_cache/struct.CacheLayer.html). It can be created with any cache that implements two traits from the [`cached`](https://crates.io/crates/cached) crate: `cached::Cached` and `cached::CloneCached`. The *current* version of `CacheLayer` is compatible only with services accepting Axum’s [`Request<Body>`](https://docs.rs/axum/latest/axum/extract/type.Request.html) and returning [`axum::response::Response`](https://docs.rs/axum/latest/axum/response/type.Response.html), thus it is not compatible with non-Axum [`tower`](https://crates.io/crates/tower) services. It’s possible to configure the layer to re-use an old expired response in case the wrapped service fails to produce a new successful response. Only successful responses are cached (responses with status codes outside of the `[200-299]` range are passed-through or ignored). The cache limits maximum size of the response’s body (128 MB by default). ## Example To cache a response over a specific route, just wrap it in a [`CacheLayer`](https://docs.rs/axum-response-cache/latest/axum_response_cache/struct.CacheLayer.html): ```rust use std::time::Duration; use axum::{Router, extract::Path, routing::get}; use axum_response_cache::CacheLayer; #[tokio::main] async fn main() { let mut router = Router::new() .route( "/hello/{name}", get(|Path(name): Path<String>| async move { format!("Hello, {name}!") }) // this will cache responses with each `{name}` for 60 seconds. .layer(CacheLayer::with_lifespan(Duration::from_secs(60))), ); let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await.unwrap(); axum::serve(listener, router).await.unwrap(); } ``` For more see [the documentation](https://docs.rs/axum-response-cache/).