Skip to content

Commit

Permalink
Wrap cache reader in BufReader for speed.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoytak committed Feb 5, 2025
1 parent 0bc9a42 commit 7a5853e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions chunk_cache/src/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl DiskCache {

let path = self.item_path(key, &cache_item)?;

let mut file_buf = match File::open(&path) {
let file_buf = match File::open(&path) {
Ok(file) => file,
Err(e) => match e.kind() {
ErrorKind::NotFound => {
Expand All @@ -255,16 +255,17 @@ impl DiskCache {
// TODO: reintroduce checksum validation of cache file, but not for every get, memoize success status per
// cache item

file_buf.seek(SeekFrom::Start(0))?;
let Ok(header) = CacheFileHeader::deserialize(&mut file_buf)
let mut file_reader = std::io::BufReader::new(file_buf);

let Ok(header) = CacheFileHeader::deserialize(&mut file_reader)
.debug_error(format!("failed to deserialize cache file header on path: {path:?}"))
else {
self.remove_item(key, &cache_item)?;
continue;
};

let start = cache_item.range.start;
let result_buf = get_range_from_cache_file(&header, &mut file_buf, range, start)?;
let result_buf = get_range_from_cache_file(&header, &mut file_reader, range, start)?;
return Ok(Some(result_buf));
}
}
Expand Down

0 comments on commit 7a5853e

Please sign in to comment.