The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(cache-disk): absolutize store directory and stamp async expiry at write time
Yujong Lee1827be1302b9
diff --git a/litellm-rust/crates/cache-disk/src/cache.rs b/litellm-rust/crates/cache-disk/src/cache.rsindex 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<S: CacheCodec, D: DiskStore, A: ValueAdapter> BaseCache for DiskCache<S, D,context: ExactCacheContext,) -> 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())}).awaitdiff --git a/litellm-rust/crates/cache-disk/src/sqlite.rs b/litellm-rust/crates/cache-disk/src/sqlite.rsindex 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<Path>) -> Result<Self, Error> {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)?;connectiondiff --git a/litellm-rust/crates/cache-disk/tests/cache.rs b/litellm-rust/crates/cache-disk/tests/cache.rsindex 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;