http-cache
An HTTP caching middleware
0.21.0
4.2M downloads/mo
#4883 most downloaded on crates.io
06chaynes/http-cache
What this package is like to depend on
Last release 21 days ago
02 Aug 2026
Release timing varies
gaps range from 1 weeks to 7 months
Most releases are documented
notes for 23 of 37 stable releases
1 version withdrawn
withdrawn after publishing
8 years old
44 releases · first in 2018
5 releases in the last 12 months
see the full history below
Release timeline
44 releases · Sep 2018 to Aug 2026Releases
latest 44-
1.0.0-alpha.702 Aug 2026 pre-releaseRelease notes
Open source →Added
RedbManagercache backend using redb for persistent, synchronous on-disk caching that requires no async runtimemanager-redbfeature flag for enablingRedbManagerStreamingCacheManager::update_metadatafor refreshing a stored entry's headers, policy, and user metadata without touching the body file. This is a required method, so existing implementations of the trait must add it.CachedRequestMethodandCacheEntryTokenresponse extensions, used by the streaming orchestrator to tell a manager which request method produced a response and which stored entry a cached response was served from
Changed
- MSRV bumped from 1.88.0 to 1.89.0
- Default cache manager changed from
manager-cacachetomanager-redb.manager-cacache(andCACacheManager) is now opt-in — enable themanager-cacachefeature to keep using it. Thecacachecrate is no longer maintained upstream. RedbManagerholds an exclusive file lock on its database: a second manager (or process) opening the same path fails at construction. Share one instance viaArcinstead. This differs from the previous defaultCACacheManager, which allowed concurrent access to one cache directory.RedbManagerstores are batched for durability: commits are flushed to disk every 64 writes (configurable viafrom_database_with_flush_interval) and on drop, so a crash can lose approximately the most recent 64 stores. Deletes commit durably, so invalidations survive a crash.StreamingManagermetadata now includes a blake3 body checksum, verified while streaming; corrupt entries error the stream and self-heal to a miss. Existing streaming cache entries from earlier alphas fail to decode and are treated as misses (re-fetched once).StreamingBody::from_file_with_sizenow streams exactlysizebytes and errors on a shorter file; it previously read to end of file, treatingsizeas a hint.StreamingManagerno longer prewarms its in-memory metadata cache at startup; hydration is lazy, soentry_count()reads 0 after a restart until keys are accessed.- Non-cacheable responses on the streaming path are now passed through without buffering (
StreamingManager::BodyisStreamingBody<UnsyncBoxBody<Bytes, StreamingError>>). Upstream body failures on that path surface as stream errors while the body is read, not as a middleware error before the response is returned. - Concurrent operations on the same cache key in
StreamingManagerare serialized with per-key locks, so racing gets/puts can no longer drop freshly written entries. StreamingManager::putwrites the response body to disk one frame at a time instead of collecting it into memory first, so peak memory no longer scales with response size. It returns a body backed by the committed on-disk entry rather than an in-memory copy.- Responses larger than
max_body_sizeare no longer an error: caching is declined and the response is served in full, uncached. A declaredContent-Lengthover the limit skips writing to disk entirely. HEAD responses are exempt, since theirContent-Lengthdescribes the entity rather than the empty body. - Responses whose received length does not match their declared
Content-Lengthare served but not cached, so a truncated response is never stored (RFC 9111 s3.3). HEAD responses are exempt. - Hop-by-hop headers are no longer written into cached entries. This covers
connection,transfer-encoding, the rest of the RFC 9111 s3.1 set, and any field names listed in aConnectionheader. Live responses are unaffected. - 304 revalidation on the streaming path updates the stored metadata in place instead of re-reading and rewriting the body file, so revalidating a large entry no longer costs a full read and write.
StreamingCacheManager::putdocuments when a stored entry becomes visible: at or after the returned body has been fully consumed. The bundledStreamingManagermakes it visible beforeputreturns, but implementations are not required to.
-
1.0.0-alpha.618 Apr 2026 pre-releaseRelease notes
Open source →Added
HttpStreamingCache::runorchestrator for streaming cache operations, eliminating duplicated logic in downstream middleware cratesFetchRequestenum for callback-based fetch dispatch in streaming pathsrun_no_cache_from_partspublic method onHttpCachefor cache-busting with pre-extracted request partsCachedUserMetadatafor preserving user metadata through 304 re-cache operationsresponse_cache_mode_fnevaluation inconditional_fetch200 branch (both paths)
Changed
StreamingManagerstorage backend replaced with an embeddedredbdatabase (for metadata) plus rawtokio::fsfiles (for response bodies), fronted bymokaas an in-memory hot cache. This replaces the previouscacache-based backend. Overwrites atomically replace prior content; there is no longer any background eviction-driven disk cleanup. Disk state is managed explicitly byput,delete, andclear. The on-disk format is not compatible with previous releases — users upgrading should delete themetadata.redbfile, thebodies/subdirectory, and thetmp/subdirectory from their cache directory before the first run on this version.- Only one
StreamingManagerinstance may point at a given cache directory at a time (enforced via the database file lock onmetadata.redb). Attempting to construct a second instance while another is alive returns an error. StreamingManager::entry_count()now returns the count of entries currently warm in the in-memory hot cache, not the total number of entries persisted on disk. When the cache has fewer entries than the configured capacity, this equals the previous value; once capacity is exceeded, cold entries remain reachable viagetbut are not counted here.- Replaced
async_traitwith native async functions in traits (RPITIT) forCacheManager,StreamingCacheManager, andMiddlewaretraits CacheAwareRateLimiter::until_key_readynow returnsPin<Box<dyn Future>>for dyn-compatibility- Removed
async-traitdependency - Cache deserialization failure logs lowered from
warntodebuglevel modify_response_before_cachingis nowpubonHttpCacheOptions
Fixed
StreamingManagernow persists cache entries across service restarts (#159). Previously the key→content mapping was only kept in memory, so cached bodies on disk became unreachable orphans after restart.- Multi-valued response headers (e.g.
Set-Cookie,Via,Link) are now preserved correctly when merging headers from revalidation responses. PreviouslyHttpResponse::update_headers, the streamingconditional_fetchFresh/304 merges, and the streaminghandle_not_modifiedpath all lost or duplicated values for same-named headers. - RFC 7234 s4.4: cache invalidation now gated on successful response status (2xx/3xx) for unsafe methods
- RFC 7234 s4.4: HEAD cache entries now invalidated alongside GET entries
conditional_fetch200 branch now checksshould_cache_responsebefore caching- Streaming path now respects
matchesflag fromBeforeRequest::Stale - Streaming path now handles all cache modes (NoCache, ForceCache, OnlyIfCached, IgnoreRules)
- Streaming 304 path preserves original user metadata instead of regenerating
modify_response_before_cachingnow called at correct point in streaming cache paths- Cache status headers set in correct order relative to
modify_responseandmanager.put - Warning header cleanup (1xx removal) on cached responses in streaming path
- 5xx stale fallback with Warning 111 in streaming conditional fetch
OnlyIfCached504 body now empty (consistent between streaming and non-streaming)
-
1.0.0-alpha.505 Mar 2026 pre-releaseRelease notes
Open source →Added
url-standardfeature flag as the new default URL implementation using theurlcrate- Transparent bincode-to-postcard migration in
CACacheManagerandMokaManager(reads legacy bincode data, writes postcard)
Changed
StreamingManagerrewritten to use cacache for disk storage with moka for metadata tracking and TinyLFU eviction- MSRV bumped from 1.85.0 to 1.88.0
- Updated
http-cache-semanticsfrom 2.1.0 to 3.0.0 - Updated
foyerto 0.22.3 - Updated
randto 0.10.0 urlcrate is now optional behindurl-standardfeature (enabled by default)- Removed
runtimemodule, streaming no longer requires runtime-specific code
Fixed
- Metadata handling with bincode serialization
CacheModeenum variant matching logic- Feature flag gates for doc tests
-
1.0.0-alpha.429 Jan 2026 pre-releaseRelease notes
Open source →Added
empty_bodymethod toStreamingCacheManagertrait for creating empty body responsesget_ref_countmethod toContentRefCounterfor non-mutating reference count checksFoyerManagercache backend using foyer for hybrid in-memory and disk cachingmanager-foyerfeature flag for enablingFoyerManagermanager-cacache-bincodeandmanager-moka-bincodefeature flags for legacy bincode serializationurl-adafeature flag for using WHATWG-compliant ada-url as an alternative to the url crateurl_parse,url_set_path,url_set_query,url_hostname,url_host_strhelper functions for URL operations
Changed
StreamingManagernow wrapsContentRefCounterinArcto ensure all clones share the same state- Atomic operations in streaming cache now use proper memory ordering (
Acquire/Release/AcqRel) instead ofRelaxed - Default serialization format changed from bincode to postcard (cache data incompatible with previous versions)
- Removed
cacache-smolandcacache-tokiofeatures in favor of tokio-only runtime cacachedependency now usestokio-runtimeby default- Removed async-std from dependency tree
Fixed
- Race condition in
remove_refusing atomiccompare_exchangeloop to prevent TOCTOU bugs - Cache size and entry count divergence when
StreamingManageris cloned - Memory leak in
deletewhere reference count was decremented but not restored on non-orphaned content - Race condition in
deleteby using non-mutatingget_ref_countinstead of remove/add pattern
-
1.0.0-alpha.318 Jan 2026 pre-release withdrawnRelease notes
Open source →Added
modify_responsefield toHttpCacheOptionsfor modifying responses before storing in cachehttp-headers-compatfeature flag for header compatibility optionsmetadatafield toHttpResponsefor storing arbitrary data with cached responsesmetadata_providerfunction toHttpCacheOptionsfor computing metadata on cache store
Changed
- MSRV is now 1.85.0
Fixed
- Serialize all header values instead of just the first value per header name
HttpHeadersserialization and insert behavior for bincode compatibility- Preserve all header values sharing the same name
-
1.0.0-alpha.225 Aug 2025 pre-releaseRelease notes
Open source →Added
max_ttlfield toHttpCacheOptionsfor controlling maximum cache duration- Support for
Durationtype inmax_ttlfield for better ergonomics and type safety - Cache duration limiting functionality that overrides longer server-specified durations while respecting shorter ones
- Enhanced cache expiration control for
CacheMode::IgnoreRulesmode rate_limiterfield toHttpCacheOptionsfor cache-aware rate limiting that only applies on cache missesCacheAwareRateLimitertrait for implementing rate limiting strategiesDomainRateLimiterfor per-domain rate limiting using governorDirectRateLimiterfor global rate limiting using governor- New
rate-limitingfeature flag for optional rate limiting functionality - Rate limiting support for streaming cache operations with seamless integration
- Simple LRU eviction policy for the
StreamingManagerwith configurable size and entry limits - Multi-runtime async support (tokio/smol) with
RwLockfor better async performance - Content deduplication using Blake3 hashing for efficient storage
- Atomic file operations using temporary files and rename for safe concurrent access
- Configurable streaming buffer size for optimal streaming performance
- Lock-free reference counting using DashMap for concurrent access
- LRU cache implementation using the
lrucrate
Changed
max_ttlimplementation automatically enforces cache duration limits by modifying response cache-control headers- Documentation updated with comprehensive examples for
max_ttlusage across all cache modes StreamingCacheConfigsimplified to essential configuration options:max_cache_size: Optional cache size limit for LRU evictionmax_entries: Optional entry count limit for LRU evictionstreaming_buffer_size: Buffer size for streaming operations (default: 8192)
- Enhanced error types and handling for streaming cache operations
- Simplified
StreamingManagerimplementation focused on core functionality and maintainability - Removed unused background cleanup and persistent reference counting infrastructure for cleaner codebase
- Improved async compatibility across tokio and smol runtimes
- Upgraded concurrent data structures to use DashMap and LRU cache
- Replaced custom implementations with established library solutions
Fixed
- Race conditions in reference counting during concurrent access
- Resource leaks in streaming cache operations when metadata write fails
- Unsafe unwrap operations in cache entry manipulation
- Inefficient URL construction replaced with safer url crate methods
- Improved error handling and recovery in streaming operations
-
1.0.0-alpha.128 Jul 2025 pre-releaseRelease notes
Open source →Added
- New streaming cache architecture for handling large HTTP responses without buffering entirely in memory
StreamingCacheManagertrait for streaming-aware cache backendsHttpCacheStreamInterfacetrait for composable streaming middleware patternsHttpStreamingCachestruct for managing streaming cache operationsStreamingManagerimplementation using file-based storageStreamingBodytype for handling both buffered and streaming scenariosCacheAnalysisstruct for better separation of cache decision logicresponse_cache_mode_fnfield toHttpCacheOptionsfor per-response cache mode overrides- New streaming feature flags:
streaming,streaming-tokio,streaming-smol
Changed
- Refactored
Middlewaretrait for better composability - Cache manager interfaces now support both buffered and streaming operations
- Enhanced separation of concerns with discrete analysis/lookup/processing steps
- Renamed
cacache-async-stdfeature tocacache-smolfor consistency - MSRV updated to 1.82.0
-
0.21.026 Jun 2025Release notes
Open source →Added
-
remove_optsfield toCACacheManagerstruct. This field is an instance ofcacache::RemoveOptsthat allows for customization of the removal options when deleting items from the cache. -
MSRV is now 1.82.0
-
-
0.20.131 Jan 2025Release notes
Open source →Changed
-
Fixed missing implementation of CacheMode::Reload variant logic.
-
MSRV is now 1.81.1
-
Updated the minimum versions of the following dependencies:
- async-trait [0.1.85]
- cacache [13.1.0]
- httpdate [1.0.2]
- moka [0.12.10]
- serde [1.0.217]
- url [2.5.4]
-
-
0.20.013 Nov 2024Release notes
Open source →Added
cache_status_headersfield toHttpCacheOptionsstruct. This field is a boolean that determines if the cache status headers should be added to the response.
-
0.19.011 Apr 2024Release notes
Open source →Changed
- Updated the minimum versions of the following dependencies:
- cacache [13.0.0]
- http [1.1.0]
- http-cache-semantics [2.1.0]
- Updated the minimum versions of the following dependencies:
-
0.18.015 Jan 2024Release notes
Open source →Added
-
overridden_cache_modemethod toMiddlewaretrait. This method allows for overriding any cache mode set in the configuration, includingcache_mode_fn. -
Derive
Defaultfor theCacheModeenum with the modeDefaultselected to be used.
-
-
0.17.001 Nov 2023Release notes
Open source →Added
-
cache_mode_fnfield toHttpCacheOptionsstruct. This is a closure that takes a&http::request::Partsand returns aCacheModeenum variant. This allows for the overriding of cache mode on a per-request basis. -
cache_bustfield toHttpCacheOptionsstruct. This is a closure that takeshttp::request::Parts,Option<CacheKey>, the default cache key (&str) and returnsVec<String>of keys to bust the cache for.
Changed
- Updated the minimum versions of the following dependencies:
- cacache [12.0.0]
-
-
0.16.029 Sep 2023Release notes
Open source →Added
-
can_cache_requestmethod toHttpCachestruct. This can be used by client implementations to determine if the request should be cached. -
run_no_cachemethod toHttpCachestruct. This should be run by client implementations if the request is determined to not be cached.
Changed
- MSRV is now 1.67.1
-
-
0.15.026 Sep 2023Release notes
Open source →Added
IgnoreRulesvariant to theCacheModeenum. This mode will ignore the HTTP headers and always store a response given it was a 200 response. It will also ignore the staleness when retrieving a response from the cache, so expiration of the cached response will need to be handled manually. If there was no cached response it will create a normal request, and will update the cache with the response.
Changed
- Updated the minimum versions of the following dependencies:
- moka [0.12.0]
-
0.14.029 Jul 2023Release notes
Open source →Added
-
cacache-async-stdfeature, which enablesasync_stdruntime support in thecacachebackend manager. This feature is enabled by default. -
cacache-tokiofeature, which enablestokioruntime support in thecacachebackend manager. This feature is disabled by default.
Changed
- Updated the minimum versions of the following dependencies:
- async-std [1.12.0]
- async-trait [0.1.72]
- serde [1.0.178]
- tokio [1.29.1]
-
-
0.13.019 Jul 2023Release notes
Open source →Added
-
CacheKeytype, a closure that takes [http::request::Parts] and returns a [String]. -
HttpCacheOptionsstruct that contains the cache key (CacheKey) and the cache options (CacheOptions).
Changed
-
CacheManagertraitget,put, anddeletemethods now require acache_keyargument rather thanmethodandurlarguments. This allows for custom keys to be specified. -
Both the
CACacheManagertrait andMokaManagerimplementation have been updated to reflect the above change. -
Updated the minimum versions of the following dependencies:
- async-trait [0.1.71]
- moka [0.11.2]
- serde [1.0.171]
-
-
0.12.005 Jun 2023Release notes
Open source →Changed
-
MSRV is now 1.66.1
-
CACacheManagerfieldpathhas changed tostd::path::PathBuf -
Updated the minimum versions of the following dependencies:
- cacache [11.6.0]
- moka [0.11.1]
- serde [1.0.163]
- url [2.4.0]
-
-
0.11.029 Mar 2023Release notes
Open source →Added
-
BoxErrortype alias forBox<dyn std::error::Error + Send + Sync>. -
BadVersionerror type for unknown http versions. -
BadHeadererror type for bad http header values.
Removed
-
CacheErrorenum. -
The following dependencies:
- anyhow
- thiserror
- miette
Changed
-
CacheErrorenum has been replaced in function byBox<dyn std::error::Error + Send + Sync>. -
Resulttypedef is nowstd::result::Result<T, BoxError>. -
Errortype for the TryFrom implentation for theHttpVersionstruct is nowBoxErrorcontaining aBadVersionerror. -
CacheManagertraitputmethod now returnsResult<(), BoxError>. -
Updated the minimum versions of the following dependencies:
- async-trait [0.1.68]
- cacache [11.4.0]
- moka [0.10.1]
- serde [1.0.159]
-
-
0.10.108 Mar 2023Release notes
Open source →Changed
- Set conditional check for
CacheError::Bincodetocfg(feature = "bincode")
- Set conditional check for
-
0.10.008 Mar 2023Release notes
Open source →Changed
-
MSRV is now 1.63.0
-
Updated the minimum versions of the following dependencies:
- async-trait [0.1.66]
- cacache [11.3.0]
- serde [1.0.154]
- thiserror [1.0.39]
-
-
0.9.224 Feb 2023Release notes
Open source →Changed
- Updated the minimum versions of the following dependencies:
- cacache [11.1.0]
- Updated the minimum versions of the following dependencies:
-
0.9.117 Feb 2023Release notes
Open source →Changed
- Updated the minimum versions of the following dependencies:
- http [0.2.9]
- Updated the minimum versions of the following dependencies:
-
0.9.017 Feb 2023Release notes
Open source →Changed
-
MSRV is now 1.62.1
-
Updated the minimum versions of the following dependencies:
- moka [0.10.0]
-
-
0.8.008 Feb 2023Release notes
Open source →Changed
-
MSRV is now 1.60.0
-
Updated the minimum versions of the following dependencies:
- anyhow [1.0.69]
- async-trait [0.1.64]
- cacache [11.0.0]
- miette [5.5.0]
- moka [0.9.7]
- serde [1.0.152]
- thiserror [1.0.38]
-
-
0.7.217 Nov 2022 -
0.7.106 Nov 2022Release notes
Open source →Changed
- Updated the minimum versions of the following dependencies:
- anyhow [1.0.66]
- async-trait [0.1.58]
- miette [5.4.1]
- moka [0.9.6]
- serde [1.0.147]
- thiserror [1.0.37]
- url [2.3.1]
- Updated the minimum versions of the following dependencies:
-
0.7.017 Jun 2022Release notes
Open source →Changed
-
The
CacheManagertrait is now implemented directly against theMokaManagerstruct rather thanArc<MokaManager>. The Arc is now internal to theMokaManagerstruct as part of thecachefield. -
Updated the minimum versions of the following dependencies:
- async-trait [0.1.56]
- http [0.2.8]
- miette [4.7.1]
- moka [0.8.5]
- serde [1.0.137]
- thiserror [1.0.31]
-
-
0.6.530 Apr 2022Release notes
Open source →Changed
- Updated the minimum versions of the following dependencies:
- http [0.2.7]
- Updated the minimum versions of the following dependencies:
-
0.6.427 Apr 2022Release notes
Open source →Added
- This changelog to keep a record of notable changes to the project.
-
0.6.323 Apr 2022Nothing published for this version
-
0.6.213 Apr 2022Nothing published for this version
-
0.6.129 Mar 2022Nothing published for this version
-
0.6.015 Mar 2022Nothing published for this version
-
0.5.010 Feb 2022Nothing published for this version
-
0.4.305 Feb 2022Nothing published for this version
-
0.4.205 Feb 2022Nothing published for this version
-
0.4.125 Jan 2022Nothing published for this version
-
0.4.023 Jan 2022Nothing published for this version
-
0.3.016 Jan 2022Nothing published for this version
-
0.2.015 Jan 2022Nothing published for this version
-
0.1.113 Jan 2022Nothing published for this version
-
0.1.013 Jan 2022Nothing published for this version
-
0.0.001 Sep 2018Nothing published for this version