1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Tower HTTP Cache
//! ==================
//!
//! `tower-http-cache` provides a composable caching layer for Tower-based services with
//! pluggable backends (in-memory, Redis, and more).
//!
//! The crate exposes a single [`CacheLayer`] that can be configured with
//! a variety of policies and storage backends. Most consumers will
//! start from [`CacheLayer::builder`] and choose an in-memory or Redis backend:
//!
//! ```no_run
//! use std::time::Duration;
//! use tower::{Service, ServiceBuilder, ServiceExt};
//! use tower_http_cache::prelude::*;
//!
//! # async fn run() -> Result<(), tower_http_cache::layer::BoxError> {
//! let layer = CacheLayer::builder(InMemoryBackend::new(1_000))
//! .ttl(Duration::from_secs(30))
//! .stale_while_revalidate(Duration::from_secs(10))
//! .build();
//!
//! let mut svc = ServiceBuilder::new()
//! .layer(layer)
//! .service(tower::service_fn(|_req| async {
//! Ok::<_, std::convert::Infallible>(http::Response::new(http_body_util::Full::from("ok")))
//! }));
//!
//! let response = svc
//! .ready()
//! .await?
//! .call(http::Request::new(()))
//! .await?;
//! # drop(response);
//! # Ok(())
//! # }
//! ```
//!
//! ## Status
//! The project is under active development. The public API is not yet stabilized.
pub use ;
pub use ;
pub use ;
pub use ;
pub use RequestId;
pub use ;
pub use ;
pub use ;