diff --git a/src/net/http.rs b/src/net/http.rs
index 210114cab..7360ed362 100644
--- a/src/net/http.rs
+++ b/src/net/http.rs
@@ -93,19 +93,28 @@ where
Ok(sender)
}
-/// Converts the URL to expiration timestamp.
-fn http_url_cache_expires(url: &str, mimetype: Option<&str>) -> i64 {
+/// Converts the URL to expiration and stale timestamps.
+fn http_url_cache_timestamps(url: &str, mimetype: Option<&str>) -> (i64, i64) {
let now = time();
- if url.ends_with(".xdc") {
- // WebXDCs expire in 5 weeks.
- now + 3600 * 24 * 35
+
+ let expires = now + 3600 * 24 * 35;
+ let stale = if url.ends_with(".xdc") {
+ // WebXDCs are never stale, they just expire.
+ expires
} else if mimetype.is_some_and(|s| s.starts_with("image/")) {
// Cache images for 1 day.
+ //
+ // As of 2024-12-12 WebXDC icons at
+ // use the same path for all app versions,
+ // so may change, but it is not critical if outdated icon is displayed.
now + 3600 * 24
} else {
- // Cache everything else for 1 hour.
+ // Revalidate everything else after 1 hour.
+ //
+ // This includes HTML, CSS and JS.
now + 3600
- }
+ };
+ (expires, stale)
}
/// Places the binary into HTTP cache.
@@ -117,14 +126,16 @@ async fn http_cache_put(context: &Context, url: &str, response: &Response) -> Re
)
.await?;
+ let (expires, stale) = http_url_cache_timestamps(url, response.mimetype.as_deref());
context
.sql
.insert(
- "INSERT OR REPLACE INTO http_cache (url, expires, blobname, mimetype, encoding)
- VALUES (?, ?, ?, ?, ?)",
+ "INSERT OR REPLACE INTO http_cache (url, expires, stale, blobname, mimetype, encoding)
+ VALUES (?, ?, ?, ?, ?, ?)",
(
url,
- http_url_cache_expires(url, response.mimetype.as_deref()),
+ expires,
+ stale,
blob.as_name(),
response.mimetype.as_deref().unwrap_or_default(),
response.encoding.as_deref().unwrap_or_default(),
@@ -136,18 +147,22 @@ async fn http_cache_put(context: &Context, url: &str, response: &Response) -> Re
}
/// Retrieves the binary from HTTP cache.
-async fn http_cache_get(context: &Context, url: &str) -> Result