Expand description
§Actix Request-Reply Cache
A Redis-backed caching middleware for Actix Web that enables response caching.
This library implements efficient HTTP response caching using Redis as a backend store, with functionality for fine-grained cache control through predicates that can examine request context to determine cacheability.
§Features
- Redis-backed HTTP response caching
- Configurable TTL (time-to-live) for cached responses
- Customizable cache key prefix
- Maximum cacheable response size configuration
- Flexible cache control through predicate functions
- Respects standard HTTP cache control headers
§Example
use actix_web::{web, App, HttpServer};
use actix_request_reply_cache::RedisCacheMiddlewareBuilder;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
// Create the cache middleware
let cache = RedisCacheMiddlewareBuilder::new("redis://127.0.0.1:6379")
.ttl(60) // Cache for 60 seconds
.cache_if(|ctx| {
// Only cache GET requests without Authorization header
ctx.method == "GET" && !ctx.headers.contains_key("Authorization")
})
.build()
.await;
HttpServer::new(move || {
App::new()
.wrap(cache.clone())
.service(web::resource("/").to(|| async { "Hello world!" }))
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}
Structs§
- Cache
Context - Context containing request information for cache operations.
- Redis
Cache Middleware - Redis-backed caching middleware for Actix Web.
- Redis
Cache Middleware Builder - Builder for configuring and creating the
RedisCacheMiddleware
. - Redis
Cache Middleware Service - Service implementation for the Redis cache middleware.