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
//! Cache storage trait.
//!
//! [`CacheStorage`] is the persistence boundary for a cache: lookup,
//! streaming insert, and invalidate, all keyed by [`CacheKey`] (URL +
//! method). A key may hold multiple entries — one per `Vary` signature
//! — and [`get`] returns the full list under a key. [`CachePolicy`] is
//! opaque to storage backends; use
//! [`CachePolicy::same_variant_as`] to dedupe by `Vary` signature when
//! finalizing an insert.
//!
//! ## Streaming
//!
//! [`put`] returns a [`PutHandle`] — an [`AsyncWrite`] sink the handler
//! writes body bytes into as they arrive from the origin. On EOF the
//! handler calls [`PutHandle::finalize`] with any trailers from the
//! body source. Dropping a `PutHandle` without finalizing aborts the
//! store; the partial data is discarded.
//!
//! On hit, [`StoredEntry::open`] returns a [`Body`] for replay. The
//! entry's stored trailers (if any) are attached to the returned Body
//! via [`Body::new_with_trailers`], so consumers see them by calling
//! [`Body::trailers`] / [`BodySource::trailers`] on the response body
//! after reaching EOF.
//!
//! [`get`]: CacheStorage::get
//! [`put`]: CacheStorage::put
//! [`AsyncWrite`]: futures_lite::AsyncWrite
//! [`Body::new_with_trailers`]: trillium_http::Body::new_with_trailers
//! [`Body::trailers`]: trillium_http::Body::trailers
//! [`BodySource::trailers`]: trillium_http::BodySource::trailers
use crateCachePolicy;
use AsyncWrite;
use ;
use ;
use Url;
/// Cache lookup key. Two responses share a key when they share method
/// + URL; `Vary` distinguishes variants within the entry list.
/// Storage backend for cached responses.
///
/// A key may carry multiple entries, one per `Vary` signature. [`get`]
/// returns the full list under a key; the cache handler picks among
/// them internally.
///
/// Writes are streaming — [`put`] returns a [`PutHandle`] that the
/// caller writes bytes into as they arrive. The handler signals end-of-
/// stream by calling [`PutHandle::finalize`]; dropping the handle
/// without finalizing aborts the write.
///
/// [`get`]: CacheStorage::get
/// [`put`]: CacheStorage::put
/// One stored response.
///
/// Returned by [`CacheStorage::get`]. Cheap to hold and pass around —
/// in-memory backends share underlying buffers via [`Arc`][std::sync::Arc],
/// and other backends typically hold only metadata until
/// [`open`][Self::open] is called. The [`Clone`] bound supports the cache
/// handler's stale-while-revalidate flow, which needs one handle to serve
/// the stale entry to the user and another to drive background
/// revalidation; for typical backends `clone` is a cheap pointer copy.
/// Streaming writer returned by [`CacheStorage::put`].
///
/// Write body bytes via the [`AsyncWrite`] impl, then call
/// [`finalize`][Self::finalize] once the body is fully consumed.
/// Dropping a `PutHandle` without finalizing aborts the write; partial
/// data MUST NOT be exposed by a subsequent [`CacheStorage::get`].