#cache #http #middleware #reqwest

http-cache-reqwest

http-cache middleware implementation for reqwest

13 releases (4 breaking)

Uses new Rust 2021

0.5.0 Jun 17, 2022
0.4.5 Apr 30, 2022
0.4.1 Mar 29, 2022
0.3.0 Feb 10, 2022
0.1.1 Jan 16, 2022

#42 in Caching

Download history 61/week @ 2022-03-08 98/week @ 2022-03-15 162/week @ 2022-03-22 315/week @ 2022-03-29 789/week @ 2022-04-05 715/week @ 2022-04-12 270/week @ 2022-04-19 318/week @ 2022-04-26 328/week @ 2022-05-03 267/week @ 2022-05-10 157/week @ 2022-05-17 152/week @ 2022-05-24 373/week @ 2022-05-31 198/week @ 2022-06-07 150/week @ 2022-06-14 153/week @ 2022-06-21

912 downloads per month
Used in rustemon

MIT/Apache

46KB
739 lines

http-cache-reqwest

CI Crates.io Docs.rs Codecov Crates.io

the http-cache logo

A caching middleware that follows HTTP caching rules, thanks to http-cache-semantics. By default, it uses cacache as the backend cache manager. Uses reqwest-middleware for middleware support.

Minimum Supported Rust Version (MSRV)

1.59.0

Install

With cargo add installed :

cargo add http-cache-reqwest

Example

use reqwest::Client;
use reqwest_middleware::{ClientBuilder, Result};
use http_cache_reqwest::{Cache, CacheMode, CACacheManager, HttpCache};

#[tokio::main]
async fn main() -> Result<()> {
    let client = ClientBuilder::new(Client::new())
        .with(Cache(HttpCache {
          mode: CacheMode::Default,
          manager: CACacheManager::default(),
          options: None,
        }))
        .build();
    client
        .get("https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching")
        .send()
        .await?;
    Ok(())
}

Features

The following features are available. By default manager-cacache is enabled.

  • manager-cacache (default): enable cacache, a high-performance disk cache, backend manager.
  • manager-moka (disabled): enable moka, a high-performance in-memory cache, backend manager.

Documentation

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~7–16MB
~326K SLoC