From 1827be1302b912ace13a56de2760a2f487025083 Mon Sep 17 00:00:00 2001 From: Yujong Lee Date: Mon, 21 Sep 2026 22:06:55 +0000 Subject: [PATCH] fix(cache-disk): absolutize store directory and stamp async expiry at write time Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm-rust/crates/cache-disk/src/cache.rs | 3 ++- litellm-rust/crates/cache-disk/src/sqlite.rs | 1 + litellm-rust/crates/cache-disk/tests/cache.rs | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/litellm-rust/crates/cache-disk/src/cache.rs b/litellm-rust/crates/cache-disk/src/cache.rs index adff078a89b..8e1223309b4 100644 --- a/litellm-rust/crates/cache-disk/src/cache.rs +++ b/litellm-rust/crates/cache-disk/src/cache.rs @@ -102,9 +102,10 @@ impl BaseCache for DiskCache Result<(), Error> { let value = self.adapter.write(self.codec.encode(&value)?); - let expire_time = context.ttl.map(|ttl| unix_now() + ttl.as_secs_f64()); + let ttl = context.ttl; let key = key.to_string(); Self::run_blocking(Arc::clone(&self.store), move |store| { + let expire_time = ttl.map(|ttl| unix_now() + ttl.as_secs_f64()); store.set(&key, value, expire_time, unix_now()) }) .await diff --git a/litellm-rust/crates/cache-disk/src/sqlite.rs b/litellm-rust/crates/cache-disk/src/sqlite.rs index ff5a44b5c38..9a36f8af6ad 100644 --- a/litellm-rust/crates/cache-disk/src/sqlite.rs +++ b/litellm-rust/crates/cache-disk/src/sqlite.rs @@ -49,6 +49,7 @@ impl DiskcacheSqliteStore { pub fn open(directory: impl AsRef) -> Result { let directory = directory.as_ref().to_path_buf(); fs::create_dir_all(&directory).map_err(|_| Error::Unavailable)?; + let directory = std::path::absolute(&directory).map_err(|_| Error::Unavailable)?; let database = directory.join("cache.db"); let connection = Connection::open(database).map_err(|_| Error::Unavailable)?; connection diff --git a/litellm-rust/crates/cache-disk/tests/cache.rs b/litellm-rust/crates/cache-disk/tests/cache.rs index 4fb77d233ec..dd1f2b1f04e 100644 --- a/litellm-rust/crates/cache-disk/tests/cache.rs +++ b/litellm-rust/crates/cache-disk/tests/cache.rs @@ -61,6 +61,25 @@ impl Sandbox { } } +#[rstest] +fn relative_store_directory_is_absolutized(sandbox: Sandbox) { + let relative = PathBuf::from(format!( + ".litellm-cache-disk-{}", + sandbox + .directory + .path() + .file_name() + .unwrap() + .to_string_lossy() + )); + let store = DiskcacheSqliteStore::open(&relative).unwrap(); + assert!(store.directory().is_absolute()); + assert!(store.directory().ends_with(&relative)); + let directory = store.directory().to_path_buf(); + drop(store); + fs::remove_dir_all(directory).unwrap(); +} + #[derive(Clone, Copy, Debug, Default)] struct TextAdapter;