http-cache-tower
An HTTP caching middleware for Tower and Hyper.
This crate provides Tower Layer and Service implementations that add HTTP caching capabilities to your HTTP clients and services.
Minimum Supported Rust Version (MSRV)
1.90.0
Install
With cargo add installed :
Features
The following features are available. By default manager-redb is enabled.
manager-redb(default): enable redb, an embedded, persistent disk cache, backend manager.manager-cacache: enable cacache, a high-performance disk cache, backend manager.manager-moka(disabled): enable moka, a high-performance in-memory cache, backend manager.manager-foyer(disabled): enable foyer, a hybrid in-memory + disk cache, backend manager.streaming(disabled): enable streaming cache support for memory-efficient handling of large responses usingStreamingManager.rate-limiting(disabled): enable cache-aware rate limiting functionality.url-ada(disabled): enable ada-url for URL parsing.
Example
Basic HTTP Cache
use HttpCacheLayer;
use RedbManager;
use ;
use ;
use Full;
use Bytes;
async
Streaming HTTP Cache
For large responses or when memory efficiency is important, use the streaming cache layer:
#
use HttpCacheStreamingLayer;
#
use StreamingManager;
#
use ;
#
use ;
#
use Full;
#
use Bytes;
#
async
#
#
Note: For memory-efficient streaming of large responses, use StreamingManager with HttpCacheStreamingLayer. For traditional caching with smaller responses, use CACacheManager or MokaManager with HttpCacheLayer.
Cache Backends
This crate supports multiple cache backends through feature flags:
manager-redb(default): Persistent disk caching using redbmanager-cacache: Disk-based caching using cacachemanager-moka: In-memory caching using moka
Integration with Hyper Client
use HttpCacheLayer;
use RedbManager;
use Client;
use TokioExecutor;
use ;
async
Documentation
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.