[go: up one dir, main page]

Expand description

A caching middleware that follows HTTP caching rules. By default it uses cacache as the backend cache manager.

Example - Surf (requires feature: client-surf)

use http_cache::{Cache, CacheMode, CACacheManager};

#[async_std::main]
async fn main() -> surf::Result<()> {
    let req = surf::get("https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching");
    surf::client()
        .with(Cache {
            mode: CacheMode::Default,
            cache_manager: CACacheManager::default(),
        })
        .send(req)
        .await?;
    Ok(())
}

Example - Reqwest (requires feature: client-reqwest)

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

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

Structs

Implements CacheManager with cacache as the backend.

Caches requests according to http spec

A basic generic type that represents an HTTP response

Enums

A generic “error” for HTTP caches

Similar to make-fetch-happen cache options. Passed in when the Cache struct is being built.

Represents an HTTP version

Traits

A trait providing methods for storing, reading, and removing cache records.

Type Definitions

A Result typedef to use with the CacheError type