Refactor cache handling logic for better readability, keep function unchanged.
This commit is contained in:
@@ -490,16 +490,7 @@ async def handle_cache(
|
||||
if hashing_kv is None or not hashing_kv.global_config.get("enable_llm_cache"):
|
||||
return None, None, None, None
|
||||
|
||||
# For default mode, only use simple cache matching
|
||||
if mode == "default":
|
||||
if exists_func(hashing_kv, "get_by_mode_and_id"):
|
||||
mode_cache = await hashing_kv.get_by_mode_and_id(mode, args_hash) or {}
|
||||
else:
|
||||
mode_cache = await hashing_kv.get_by_id(mode) or {}
|
||||
if args_hash in mode_cache:
|
||||
return mode_cache[args_hash]["return"], None, None, None
|
||||
return None, None, None, None
|
||||
|
||||
if mode != "default":
|
||||
# Get embedding cache configuration
|
||||
embedding_cache_config = hashing_kv.global_config.get(
|
||||
"embedding_cache_config",
|
||||
@@ -531,6 +522,9 @@ async def handle_cache(
|
||||
if best_cached_response is not None:
|
||||
return best_cached_response, None, None, None
|
||||
else:
|
||||
return None, quantized, min_val, max_val
|
||||
|
||||
# For default mode(extract_entities or naive query) or is_embedding_cache_enabled is False
|
||||
# Use regular cache
|
||||
if exists_func(hashing_kv, "get_by_mode_and_id"):
|
||||
mode_cache = await hashing_kv.get_by_mode_and_id(mode, args_hash) or {}
|
||||
@@ -539,7 +533,7 @@ async def handle_cache(
|
||||
if args_hash in mode_cache:
|
||||
return mode_cache[args_hash]["return"], None, None, None
|
||||
|
||||
return None, quantized, min_val, max_val
|
||||
return None, None, None, None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
Reference in New Issue
Block a user