0.35.4
This commit is contained in:
1 parent
c038ad44b3
commit
cd3c28d390
33 files changed
+807
-221
No files matched your search
Vendored
+21
-6
@@ -43,7 +43,18 @@ impl Cache {
|
||||
ticket.freshness_headers(),
|
||||
);
|
||||
if state.servable() {
|
||||
let sequence = store.next_sequence();
|
||||
// Approximate LRU: an entry already among the most recently used
|
||||
// eighth of the store is not re-linked on every hit. This keeps the
|
||||
// global HOT lock short for popular objects without changing which
|
||||
// cold entries are evicted first.
|
||||
let promote = store
|
||||
.entries
|
||||
.get(&storage_key)
|
||||
.is_some_and(|entry| {
|
||||
store.sequence.saturating_sub(entry.sequence)
|
||||
> (store.entries.len() as u64) / 8
|
||||
});
|
||||
let sequence = if promote { store.next_sequence() } else { 0 };
|
||||
let (
|
||||
old_sequence,
|
||||
headers,
|
||||
@@ -59,7 +70,9 @@ impl Cache {
|
||||
let old_sequence = entry.sequence;
|
||||
entry.hits = entry.hits.saturating_add(1);
|
||||
entry.last_access = Instant::now();
|
||||
entry.sequence = sequence;
|
||||
if promote {
|
||||
entry.sequence = sequence;
|
||||
}
|
||||
(
|
||||
old_sequence,
|
||||
Arc::clone(&entry.headers),
|
||||
@@ -72,8 +85,10 @@ impl Cache {
|
||||
entry.body.len(),
|
||||
)
|
||||
};
|
||||
store.lru.remove(&old_sequence);
|
||||
store.lru.insert(sequence, storage_key);
|
||||
if promote {
|
||||
store.lru.remove(&old_sequence);
|
||||
store.lru.insert(sequence, storage_key);
|
||||
}
|
||||
self.counters.hits.fetch_add(1, Ordering::Relaxed);
|
||||
drop(store);
|
||||
|
||||
@@ -88,7 +103,7 @@ impl Cache {
|
||||
response.extensions_mut().insert(crate::compression::Skip);
|
||||
}
|
||||
response.headers_mut().insert(::http::header::AGE,
|
||||
HeaderValue::from_str(&age.to_string()).expect("integer header"),
|
||||
HeaderValue::from(age),
|
||||
);
|
||||
self.domain_stats
|
||||
.saved_body_hit(&ticket.scope, &ticket.domain, body_bytes);
|
||||
@@ -285,7 +300,7 @@ impl Cache {
|
||||
response.extensions_mut().insert(crate::compression::Skip);
|
||||
}
|
||||
response.headers_mut().insert(::http::header::AGE,
|
||||
HeaderValue::from_str(&age.to_string()).expect("integer header"),
|
||||
HeaderValue::from(age),
|
||||
);
|
||||
self.domain_stats
|
||||
.saved_body_hit(&ticket.scope, &ticket.domain, entry.body_bytes);
|
||||
|
||||
Reference in new issue
Block a user