This commit is contained in:
Mateusz Gruszczyński committed 2026-10-22 15:31:47 +02:00
1 parent 3ea00045bf
commit 1cd6b7ac99
22 files changed
+550 -149

No files matched your search

+4
View File
@@ -61,6 +61,10 @@ impl Settings {
valid_relative_cache_path(&self.cold_path),
"cache.cold_path must be a simple relative path inside the data directory"
);
ensure!(
self.varnish_grace_seconds <= 604_800,
"cache.varnish_grace_seconds must be 0..604800"
);
ensure!(
(1..=604_800).contains(&self.max_ttl_seconds)
&& self.default_ttl_seconds <= self.max_ttl_seconds,
+3
View File
@@ -89,6 +89,8 @@ pub struct Settings {
pub enabled: bool,
/// Ignore client freshness directives on cache lookups, like Varnish builtin VCL.
pub varnish_compatible: bool,
/// Implicit grace in seconds for eligible fresh-at-storage cached responses.
pub varnish_grace_seconds: u64,
pub memory_preset: Option<MemoryPreset>,
pub max_bytes: usize,
pub max_object_bytes: usize,
@@ -143,6 +145,7 @@ impl Default for Settings {
Self {
enabled: true,
varnish_compatible: true,
varnish_grace_seconds: 60,
memory_preset: None,
max_bytes: 256 * 1024 * 1024,
max_object_bytes: 16 * 1024 * 1024,
+9 -4
View File
@@ -132,13 +132,18 @@ fn stale_mode(
return None;
}
let stale_for = age.saturating_sub(ttl);
let max_stale = client_max_stale(request_headers);
// An explicit client limit must also constrain implicit Varnish grace.
// In particular, max-stale=0 must not serve a stale representation.
if matches!(max_stale, Some(Some(limit)) if stale_for > limit) {
return None;
}
if stale_while_revalidate > 0 && stale_for <= stale_while_revalidate {
return Some(true);
}
match client_max_stale(request_headers) {
Some(None) => Some(false),
Some(Some(limit)) if stale_for <= limit => Some(false),
_ => None,
match max_stale {
Some(None) | Some(Some(_)) => Some(false),
None => None,
}
}