MCPcopy Index your code
hub / github.com/Firstyear/opensuse-proxy-cache / get

Method get

arc-disk-cache/src/lib.rs:483–535  ·  view source on GitHub ↗
(&self, q: &Q)

Source from the content-addressed store, hash-verified

481 }
482
483 pub fn get<Q>(&self, q: &Q) -> Option<CacheObj<K, D>>
484 where
485 K: Borrow<Q>,
486 Q: Hash + Eq + Ord + ?Sized,
487 {
488 let mut rtxn = self.cache.read();
489 let maybe_obj = rtxn
490 .get(q)
491 .and_then(|obj| {
492 let mut file = File::open(&obj.fhandle.path).ok()?;
493
494 let amt = file
495 .metadata()
496 .map(|m| m.len() as usize)
497 .map_err(|e| {
498 error!("Unable to access metadata -> {:?}", e);
499 })
500 .ok()?;
501
502 if !self.durable_fs {
503 if amt < CHECK_INLINE {
504 let crc_ck = crc32c_len(&mut file).ok()?;
505 if crc_ck != obj.fhandle.crc {
506 warn!("file potentially corrupted - {:?}", obj.fhandle.meta_path);
507 return None;
508 }
509 } else {
510 info!("Skipping crc check, file too large");
511 }
512 }
513
514 Some(obj)
515 })
516 .cloned();
517
518 // We manually quiesce and finish for stat management here
519 // In theory, this should only affect hit counts since evict / include
520 // should only occur in a write with how this is setup
521 rtxn.finish();
522
523 let mut stat_guard = self.stats.write();
524 stat_guard.ops += 1;
525 if maybe_obj.is_some() {
526 stat_guard.hits += 1;
527 }
528 stat_guard.ratio = (f64::from(stat_guard.hits) / f64::from(stat_guard.ops)) * 100.0;
529
530 let stats = self.cache.try_quiesce_stats(TraceStat::default());
531 stat_guard.update(stats);
532 stat_guard.commit();
533
534 maybe_obj
535 }
536
537 pub fn path(&self) -> &Path {
538 &self.content_dir

Callers 1

server_it_worksFunction · 0.45

Calls 2

crc32c_lenFunction · 0.85
updateMethod · 0.80

Tested by

no test coverage detected