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