Commit

Cache hits are counted, not only their bytes

cache.memory_hit and cache.edge_hit went through record_bytes, which adds bytes to a meter without counting it, so every hit read as 0.

syntaqxcommitted Parentc867f21Browse files
1 file+2−20/1 viewed
+2−2
637637 async fn cached_at(&self, path: &str, forever: bool) -> Option<Vec<u8>> {
638638 let url = self.cache_url(path);
639639 if forever && let Some(bytes) = MEMORY.with(|memory| memory.borrow().get(&url)) {
640− meters::record_bytes("cache.memory_hit", &self.key, 0, bytes.len() as u64);
640+ meters::record("cache.memory_hit", &self.key, 0, bytes.len() as u64);
641641 return Some(bytes);
642642 }
643643 let found = match worker::Cache::default().get(url.clone(), false).await {
646646 };
647647 match &found {
648648 Some(bytes) => {
649− meters::record_bytes("cache.edge_hit", &self.key, 0, bytes.len() as u64);
649+ meters::record("cache.edge_hit", &self.key, 0, bytes.len() as u64);
650650 if forever {
651651 MEMORY.with(|memory| memory.borrow_mut().put(url, bytes));
652652 }