1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//! HTTP caching manager implementation using QuickCache.
//!
//! This crate provides a [`CacheManager`] implementation using the
//! [QuickCache](https://github.com/arthurprs/quick-cache) in-memory cache.
//! QuickCache is an in-memory cache that can be used for applications that
//! need cache access with predictable memory usage.
//!
//! ## Basic Usage
//!
//! ```rust
//! use http_cache_quickcache::QuickManager;
//! use quick_cache::sync::Cache;
//!
//! // Create a cache with a maximum of 1000 entries
//! let cache = Cache::new(1000);
//! let manager = QuickManager::new(cache);
//!
//! // Use with any HTTP cache implementation that accepts a CacheManager
//! ```
//!
//! ## Integration with HTTP Cache Middleware
//!
//! ### With Tower Services
//!
//! ```no_run
//! use tower::{Service, ServiceExt};
//! use http::{Request, Response, StatusCode};
//! use http_body_util::Full;
//! use bytes::Bytes;
//! use http_cache_quickcache::QuickManager;
//! use std::convert::Infallible;
//!
//! // Example Tower service that uses QuickManager for caching
//! #[derive(Clone)]
//! struct CachingService {
//! cache_manager: QuickManager,
//! }
//!
//! impl Service<Request<Full<Bytes>>> for CachingService {
//! type Response = Response<Full<Bytes>>;
//! type Error = Box<dyn std::error::Error + Send + Sync>;
//! type Future = std::pin::Pin<Box<dyn std::future::Future<Output = Result<Self::Response, Self::Error>> + Send>>;
//!
//! fn poll_ready(&mut self, _cx: &mut std::task::Context<'_>) -> std::task::Poll<Result<(), Self::Error>> {
//! std::task::Poll::Ready(Ok(()))
//! }
//!
//! fn call(&mut self, req: Request<Full<Bytes>>) -> Self::Future {
//! let manager = self.cache_manager.clone();
//! Box::pin(async move {
//! // Cache logic using the manager would go here
//! let response = Response::builder()
//! .status(StatusCode::OK)
//! .body(Full::new(Bytes::from("Hello from cached service!")))?;
//! Ok(response)
//! })
//! }
//! }
//! ```
//!
//! ### With Hyper
//!
//! ```no_run
//! use hyper::{Request, Response, StatusCode, body::Incoming};
//! use http_body_util::Full;
//! use bytes::Bytes;
//! use http_cache_quickcache::QuickManager;
//! use std::convert::Infallible;
//!
//! async fn handle_request(
//! _req: Request<Incoming>,
//! cache_manager: QuickManager,
//! ) -> Result<Response<Full<Bytes>>, Infallible> {
//! // Use cache_manager here for caching responses
//! Ok(Response::builder()
//! .status(StatusCode::OK)
//! .header("cache-control", "max-age=3600")
//! .body(Full::new(Bytes::from("Hello from Hyper with caching!")))
//! .unwrap())
//! }
//! ```
//!
//! ## Usage Characteristics
//!
//! QuickCache is designed for scenarios where:
//! - You need predictable memory usage
//! - In-memory storage is acceptable
//! - You want to avoid complex configuration
//! - Memory-based caching fits your use case
//!
//! For applications that need persistent caching across restarts, consider using
//! [`CACacheManager`](https://docs.rs/http-cache/latest/http_cache/struct.CACacheManager.html)
//! instead, which provides disk-based storage.
use ;
use ;
use CachePolicy;
use Cache;
use ;
/// HTTP cache manager implementation using QuickCache.
///
/// This manager provides in-memory caching using the QuickCache library and implements
/// the [`CacheManager`] trait for HTTP caching support.
///
/// ## Examples
///
/// ### Basic Usage
///
/// ```rust
/// use http_cache_quickcache::QuickManager;
/// use quick_cache::sync::Cache;
///
/// // Create a cache with 1000 entry limit
/// let cache = Cache::new(1000);
/// let manager = QuickManager::new(cache);
/// ```
///
/// ## Default Configuration
///
/// The default configuration creates a cache with 42 entries:
///
/// ```rust
/// use http_cache_quickcache::QuickManager;
///
/// let manager = QuickManager::default();
/// ```