aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-04-19 14:40:20 +0200
committermetamuffin <metamuffin@disroot.org>2025-04-19 14:40:20 +0200
commit121722729caaacbbd430b0a58c302389575acd05 (patch)
treeed3e2006c677a21f5cdba6d0a59f2b81c79d4cb6
parente799a338b8691837e88d1570158935d316c9efb0 (diff)
downloadjellything-121722729caaacbbd430b0a58c302389575acd05.tar
jellything-121722729caaacbbd430b0a58c302389575acd05.tar.bz2
jellything-121722729caaacbbd430b0a58c302389575acd05.tar.zst
buffered io sync memory cache
-rw-r--r--base/src/cache.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/base/src/cache.rs b/base/src/cache.rs
index 40c6e7b..9c12d3d 100644
--- a/base/src/cache.rs
+++ b/base/src/cache.rs
@@ -17,7 +17,7 @@ use std::{
fs::rename,
future::Future,
hash::{Hash, Hasher},
- io::Seek,
+ io::{Seek, Write},
path::PathBuf,
sync::{
atomic::{AtomicBool, AtomicUsize, Ordering},
@@ -178,13 +178,15 @@ where
}
}
- let location = cache_file(kind, &key, move |mut file| {
+ let location = cache_file(kind, &key, move |file| {
let object = generate()?;
+ let mut file = std::io::BufWriter::new(file);
bincode::encode_into_std_write(&object, &mut file, bincode::config::standard())
.context("encoding cache object")?;
+ file.flush()?;
Ok(())
})?;
- let mut file = std::fs::File::open(location.abs())?;
+ let mut file = std::io::BufReader::new(std::fs::File::open(location.abs())?);
let object = bincode::decode_from_std_read::<T, _, _>(&mut file, bincode::config::standard())
.context("decoding cache object")?;
let object = Arc::new(object);