Skip to content

Commit 881db9e

Browse files
gdavidssonandrewhavck
authored andcommitted
Add/polish some comments
1 parent f54d17a commit 881db9e

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

.bleep

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a1e399e99a67e743d00ba50ba7c3999c25136fe5
1+
d37f942d73e5b2921f026cf6e2b1f93a216d895b

pingora-cache/src/filters.rs

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ pub fn request_cacheable(req_header: &ReqHeader) -> bool {
3333
///
3434
/// `cache_control` is the parsed [CacheControl] from the response header. It is a standalone
3535
/// argument so that caller has the flexibility to choose to use, change or ignore it.
36-
// TODO: vary processing
3736
pub fn resp_cacheable(
3837
cache_control: Option<&CacheControl>,
3938
resp_header: &ResponseHeader,

pingora-proxy/src/proxy_cache.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,34 @@ impl<SV> HttpProxy<SV> {
8383
match session.cache.cache_lookup().await {
8484
Ok(res) => {
8585
if let Some((mut meta, handler)) = res {
86-
// vary logic
87-
// because this branch can be called multiple times in a loop, and we only
86+
// Vary logic
87+
// Because this branch can be called multiple times in a loop, and we only
8888
// need to update the vary once, check if variance is already set to
89-
// prevent unnecessary vary lookups
89+
// prevent unnecessary vary lookups.
9090
let cache_key = session.cache.cache_key();
9191
if let Some(variance) = cache_key.variance_bin() {
92-
// adhoc double check the variance found is the variance we want
92+
// We've looked up a secondary slot.
93+
// Adhoc double check that the variance found is the variance we want.
9394
if Some(variance) != meta.variance() {
9495
warn!("Cache variance mismatch, {variance:?}, {cache_key:?}");
9596
session.cache.disable(NoCacheReason::InternalError);
9697
break None;
9798
}
9899
} else {
100+
// Basic cache key; either variance is off, or this is the primary slot.
99101
let req_header = session.req_header();
100102
let variance = self.inner.cache_vary_filter(&meta, ctx, req_header);
101103
if let Some(variance) = variance {
104+
// Variance is on. This is the primary slot.
102105
if !session.cache.cache_vary_lookup(variance, &meta) {
103-
// cache key variance updated, need to lookup again
106+
// This wasn't the desired variant. Updated cache key variance, cause another
107+
// lookup to get the desired variant, which would be in a secondary slot.
104108
continue;
105109
}
106-
} //else: vary is not in use
110+
} // else: vary is not in use
107111
}
108112

109-
// either no variance or the current handler is the variance
113+
// Either no variance, or the current handler targets the correct variant.
110114

111115
// hit
112116
// TODO: maybe round and/or cache now()
@@ -206,6 +210,7 @@ impl<SV> HttpProxy<SV> {
206210
} else {
207211
// cache miss
208212
if session.cache.is_cache_locked() {
213+
// Another request is filling the cache; try waiting til that's done and retry.
209214
let lock_status = session.cache.cache_lock_wait().await;
210215
if self.handle_lock_status(session, ctx, lock_status) {
211216
continue;

pingora-proxy/src/proxy_trait.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub trait ProxyHttp {
5757

5858
/// This filter decides if the request is cacheable and what cache backend to use
5959
///
60-
/// The caller can interact with `Session.cache` to enabled caching.
60+
/// The caller can interact with `Session.cache` to enable caching.
6161
///
6262
/// By default this filter does nothing which effectively disables caching.
6363
// Ideally only session.cache should be modified, TODO: reflect that in this interface
@@ -127,7 +127,7 @@ pub trait ProxyHttp {
127127

128128
/// Decide how to generate cache vary key from both request and response
129129
///
130-
/// None means no variance is need.
130+
/// None means no variance is needed.
131131
fn cache_vary_filter(
132132
&self,
133133
_meta: &CacheMeta,

0 commit comments

Comments
 (0)