Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ jobs:
- uses: taiki-e/install-action@cargo-llvm-cov
- run: |
cargo llvm-cov clean --workspace
cargo llvm-cov --no-report --no-default-features --package http-cache --features manager-cacache,cacache-async-std,with-http-types,manager-moka
cargo llvm-cov --no-report --no-default-features --package http-cache --features manager-cacache,cacache-tokio
cargo llvm-cov --no-report --package http-cache-surf --features manager-moka
cargo llvm-cov --no-report --package http-cache-reqwest --features manager-moka
cargo llvm-cov --no-report --no-default-features --package http-cache --features manager-cacache,cacache-smol,with-http-types,manager-moka,streaming-smol
cargo llvm-cov --no-report --no-default-features --package http-cache --features manager-cacache,cacache-tokio,with-http-types,manager-moka,streaming-tokio
cargo llvm-cov --no-report --package http-cache-surf --all-features
cargo llvm-cov --no-report --package http-cache-reqwest --all-features
cargo llvm-cov --no-report --package http-cache-tower --all-features
cargo llvm-cov --no-report --package http-cache-quickcache --all-features
cargo llvm-cov report --lcov --output-path lcov.info
- uses: codecov/codecov-action@v5
with:
Expand Down
66 changes: 0 additions & 66 deletions .github/workflows/http-cache-mokadeser.yml

This file was deleted.

4 changes: 3 additions & 1 deletion .github/workflows/http-cache-quickcache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ jobs:
env:
RUSTFLAGS: --cfg docsrs
RUSTDOCFLAGS: --cfg docsrs -Dwarnings
- run: cargo doc --no-deps --document-private-items
- run: |
cargo doc --no-deps --document-private-items
cargo test --doc --all-features
4 changes: 3 additions & 1 deletion .github/workflows/http-cache-reqwest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ jobs:
env:
RUSTFLAGS: --cfg docsrs
RUSTDOCFLAGS: --cfg docsrs -Dwarnings
- run: cargo doc --no-deps --document-private-items
- run: |
cargo doc --no-deps --document-private-items
cargo test --doc --all-features
4 changes: 3 additions & 1 deletion .github/workflows/http-cache-surf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ jobs:
env:
RUSTFLAGS: --cfg docsrs
RUSTDOCFLAGS: --cfg docsrs -Dwarnings
- run: cargo doc --no-deps --document-private-items
- run: |
cargo doc --no-deps --document-private-items
cargo test --doc --all-features
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
name: http-cache-darkbird
name: http-cache-tower

on:
push:
branches: [main]
pull_request:
workflow_dispatch:

env:
CARGO_TERM_COLOR: always

concurrency:
group: ${{ github.ref }}-http-cache-darkbird
group: ${{ github.ref }}-http-cache-tower
cancel-in-progress: true

defaults:
run:
working-directory: ./http-cache-darkbird
working-directory: ./http-cache-tower

jobs:
fmt:
Expand Down Expand Up @@ -41,6 +44,16 @@ jobs:
- run: |
cargo test --all-targets --all-features

examples:
name: Test examples
needs: [fmt]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: |
cargo run --example streaming_memory_profile --features streaming

clippy:
name: Check clippy
needs: [fmt, test]
Expand All @@ -63,4 +76,6 @@ jobs:
env:
RUSTFLAGS: --cfg docsrs
RUSTDOCFLAGS: --cfg docsrs -Dwarnings
- run: cargo doc --no-deps --document-private-items
- run: |
cargo doc --no-deps --document-private-items
cargo test --doc --all-features
13 changes: 8 additions & 5 deletions .github/workflows/http-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: |
cargo test --all-targets --no-default-features --features manager-cacache,cacache-async-std,with-http-types,manager-moka
cargo test --all-targets --no-default-features --features manager-cacache,cacache-tokio
cargo test --all-targets --no-default-features --features manager-cacache,cacache-smol,with-http-types,manager-moka,streaming-smol
cargo test --all-targets --no-default-features --features manager-cacache,cacache-tokio,with-http-types,manager-moka,streaming-tokio

clippy:
name: Check clippy
Expand All @@ -55,8 +55,8 @@ jobs:
with:
components: "clippy"
- run: |
cargo clippy --lib --tests --all-targets --no-default-features --features manager-cacache,cacache-async-std,with-http-types,manager-moka -- -D warnings
cargo clippy --lib --tests --all-targets --no-default-features --features manager-cacache,cacache-tokio -- -D warnings
cargo clippy --lib --tests --all-targets --no-default-features --features manager-cacache,cacache-smol,with-http-types,manager-moka,streaming-smol -- -D warnings
cargo clippy --lib --tests --all-targets --no-default-features --features manager-cacache,cacache-tokio,with-http-types,manager-moka,streaming-tokio -- -D warnings

docs:
name: Build docs
Expand All @@ -68,4 +68,7 @@ jobs:
env:
RUSTFLAGS: --cfg docsrs
RUSTDOCFLAGS: --cfg docsrs -Dwarnings
- run: cargo doc --no-deps --document-private-items
- run: |
cargo doc --no-deps --document-private-items
cargo test --doc --no-default-features --features manager-cacache,cacache-smol,with-http-types,manager-moka,streaming-smol
cargo test --doc --no-default-features --features manager-cacache,cacache-tokio,with-http-types,manager-moka,streaming-tokio
2 changes: 2 additions & 0 deletions .github/workflows/msrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
- http-cache
- http-cache-reqwest
- http-cache-surf
- http-cache-tower
- http-cache-quickcache
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ target/
Cargo.lock
**/*.rs.bk
http-cacache/
http-darkbird/
/.idea
/public
/.DS_Store
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ members = [
"http-cache",
"http-cache-reqwest",
"http-cache-surf",
"http-cache-quickcache"
"http-cache-quickcache",
"http-cache-tower"
]
2 changes: 2 additions & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
- [Client Implementations](./clients/clients.md)
- [reqwest](./clients/reqwest.md)
- [surf](./clients/surf.md)
- [tower](./clients/tower.md)
- [Backend Cache Manager Implementations](./managers/managers.md)
- [cacache](./managers/cacache.md)
- [moka](./managers/moka.md)
- [quick_cache](./managers/quick-cache.md)
- [streaming_cache](./managers/streaming_cache.md)
8 changes: 6 additions & 2 deletions docs/src/clients/clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ The following client implementations are provided by this crate:

## [reqwest](./reqwest.md)

The [`http-cache-reqwest`](https://github.com/06chaynes/http-cache/tree/latest/http-cache-reqwest) crate provides a [`Middleware`](https://docs.rs/http-cache/latest/http_cache/trait.Middleware.html) implementation for the [`reqwest`](https://github.com/seanmonstar/reqwest) HTTP client.
The [`http-cache-reqwest`](https://github.com/06chaynes/http-cache/tree/main/http-cache-reqwest) crate provides a [`Middleware`](https://docs.rs/http-cache/latest/http_cache/trait.Middleware.html) implementation for the [`reqwest`](https://github.com/seanmonstar/reqwest) HTTP client.

## [surf](./surf.md)

The [`http-cache-surf`](https://github.com/06chaynes/http-cache/tree/latest/http-cache-surf) crate provides a [`Middleware`](https://docs.rs/http-cache/latest/http_cache/trait.Middleware.html) implementation for the [`surf`](https://github.com/http-rs/surf) HTTP client.
The [`http-cache-surf`](https://github.com/06chaynes/http-cache/tree/main/http-cache-surf) crate provides a [`Middleware`](https://docs.rs/http-cache/latest/http_cache/trait.Middleware.html) implementation for the [`surf`](https://github.com/http-rs/surf) HTTP client.

## [tower](./tower.md)

The [`http-cache-tower`](https://github.com/06chaynes/http-cache/tree/main/http-cache-tower) crate provides Tower Layer and Service implementations for caching HTTP requests and responses. It supports both regular and streaming cache operations for memory-efficient handling of large responses.
62 changes: 61 additions & 1 deletion docs/src/clients/reqwest.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# reqwest

The [`http-cache-reqwest`](https://github.com/06chaynes/http-cache/tree/latest/http-cache-reqwest) crate provides a [`Middleware`](https://docs.rs/http-cache/latest/http_cache/trait.Middleware.html) implementation for the [`reqwest`](https://github.com/seanmonstar/reqwest) HTTP client. It accomplishes this by utilizing [`reqwest_middleware`](https://github.com/TrueLayer/reqwest-middleware).
The [`http-cache-reqwest`](https://github.com/06chaynes/http-cache/tree/main/http-cache-reqwest) crate provides a [`Middleware`](https://docs.rs/http-cache/latest/http_cache/trait.Middleware.html) implementation for the [`reqwest`](https://github.com/seanmonstar/reqwest) HTTP client. It accomplishes this by utilizing [`reqwest_middleware`](https://github.com/TrueLayer/reqwest-middleware).

## Getting Started

Expand All @@ -12,6 +12,7 @@ cargo add http-cache-reqwest

- `manager-cacache`: (default) Enables the [`CACacheManager`](https://docs.rs/http-cache/latest/http_cache/struct.CACacheManager.html) backend cache manager.
- `manager-moka`: Enables the [`MokaManager`](https://docs.rs/http-cache/latest/http_cache/struct.MokaManager.html) backend cache manager.
- `streaming`: Enables streaming cache support for memory-efficient handling of large response bodies.

## Usage

Expand Down Expand Up @@ -40,3 +41,62 @@ async fn main() -> Result<()> {
Ok(())
}
```

## Streaming Cache Support

For memory-efficient caching of large response bodies, you can use the streaming cache feature. This is particularly useful for handling large files, media content, or API responses without loading the entire response into memory.

To enable streaming cache support, add the `streaming` feature to your `Cargo.toml`:

```toml
[dependencies]
http-cache-reqwest = { version = "1.0", features = ["streaming"] }
```

### Basic Streaming Example

```rust
use http_cache::StreamingManager;
use http_cache_reqwest::StreamingCache;
use reqwest::Client;
use reqwest_middleware::ClientBuilder;
use std::path::PathBuf;
use futures_util::StreamExt;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// Create streaming cache manager
let cache_manager = StreamingManager::new(PathBuf::from("./cache"), true);
let streaming_cache = StreamingCache::new(cache_manager);

// Build client with streaming cache
let client = ClientBuilder::new(Client::new())
.with(streaming_cache)
.build();

// Make request to large content
let response = client
.get("https://example.com/large-file.zip")
.send()
.await?;

// Stream the response body
let mut stream = response.bytes_stream();
let mut total_bytes = 0;

while let Some(chunk) = stream.next().await {
let chunk = chunk?;
total_bytes += chunk.len();
// Process chunk without loading entire response into memory
}

println!("Downloaded {total_bytes} bytes");
Ok(())
}
```

### Key Benefits of Streaming Cache

- **Memory Efficiency**: Large responses are streamed directly to/from disk cache without buffering in memory
- **Performance**: Cached responses can be streamed immediately without waiting for complete download
- **Scalability**: Handle responses of any size without memory constraints
16 changes: 10 additions & 6 deletions docs/src/clients/surf.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# surf

The [`http-cache-surf`](https://github.com/06chaynes/http-cache/tree/latest/http-cache-surf) crate provides a [`Middleware`](https://docs.rs/http-cache/latest/http_cache/trait.Middleware.html) implementation for the [`surf`](https://github.com/http-rs/surf) HTTP client.
The [`http-cache-surf`](https://github.com/06chaynes/http-cache/tree/main/http-cache-surf) crate provides a [`Middleware`](https://docs.rs/http-cache/latest/http_cache/trait.Middleware.html) implementation for the [`surf`](https://github.com/http-rs/surf) HTTP client.

## Getting Started

Expand All @@ -21,17 +21,21 @@ After constructing our client, we will make a request to the [MDN Caching Docs](

```rust
use http_cache_surf::{Cache, CacheMode, CACacheManager, HttpCache, HttpCacheOptions};
use surf::Client;
use macro_rules_attribute::apply;
use smol_macros::main;

#[async_std::main]
#[apply(main!)]
async fn main() -> surf::Result<()> {
let req = surf::get("https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching");
surf::client()
let client = Client::new()
.with(Cache(HttpCache {
mode: CacheMode::Default,
manager: CACacheManager::default(),
options: HttpCacheOptions::default(),
}))
.send(req)
}));

client
.get("https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching")
.await?;
Ok(())
}
Expand Down
Loading
Loading