Crates.io | http-cache-quickcache |
lib.rs | http-cache-quickcache |
version | 1.0.0-alpha.2 |
created_at | 2023-02-17 00:35:03.482183+00 |
updated_at | 2025-08-25 03:15:58.594262+00 |
description | http-cache manager implementation for quick-cache |
homepage | https://http-cache.rs |
repository | https://github.com/06chaynes/http-cache |
max_upload_size | |
id | 787148 |
size | 78,210 |
An http-cache manager implementation for quick-cache.
1.82.0
With cargo add installed :
cargo add http-cache-quickcache
use tower::{Service, ServiceExt};
use http::{Request, Response, StatusCode};
use http_body_util::Full;
use bytes::Bytes;
use http_cache_quickcache::QuickManager;
use std::convert::Infallible;
// Example Tower service that uses QuickManager for caching
#[derive(Clone)]
struct CachingService {
cache_manager: QuickManager,
}
impl Service<Request<Full<Bytes>>> for CachingService {
type Response = Response<Full<Bytes>>;
type Error = Box<dyn std::error::Error + Send + Sync>;
type Future = std::pin::Pin<Box<dyn std::future::Future<Output = Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(&mut self, _cx: &mut std::task::Context<'_>) -> std::task::Poll<Result<(), Self::Error>> {
std::task::Poll::Ready(Ok(()))
}
fn call(&mut self, req: Request<Full<Bytes>>) -> Self::Future {
let manager = self.cache_manager.clone();
Box::pin(async move {
// Cache logic using the manager would go here
let response = Response::builder()
.status(StatusCode::OK)
.body(Full::new(Bytes::from("Hello from cached service!")))?;
Ok(response)
})
}
}
use hyper::{Request, Response, StatusCode, body::Incoming};
use http_body_util::Full;
use bytes::Bytes;
use http_cache_quickcache::QuickManager;
use std::convert::Infallible;
async fn handle_request(
_req: Request<Incoming>,
cache_manager: QuickManager,
) -> Result<Response<Full<Bytes>>, Infallible> {
// Use cache_manager here for caching responses
Ok(Response::builder()
.status(StatusCode::OK)
.header("cache-control", "max-age=3600")
.body(Full::new(Bytes::from("Hello from Hyper with caching!")))
.unwrap())
}
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.