[Bugfix][EC Connector] Don't create hash directories on cache-miss lookups in ECExampleConnector (#60826)

Signed-off-by: zhouyou9505 <zhouyou9505@gmail.com>
This commit is contained in:
zhouyou
2026-10-13 15:59:48 +08:00
committed by GitHub
parent 2cc2e68d1c
commit 3ad096faf8
2 changed files with 20 additions and 6 deletions
@@ -202,7 +202,7 @@ class ECExampleConnector(ECConnectorBase):
def _found_match_for_mm_data(self, mm_hash) -> bool:
"""Check if the cache is hit for the request."""
filename = self._generate_filename_debug(mm_hash)
filename = self._generate_filename_debug(mm_hash, create_folder=False)
return os.path.exists(filename)
def _generate_foldername_debug(
@@ -219,11 +219,13 @@ class ECExampleConnector(ECConnectorBase):
os.makedirs(foldername, exist_ok=True)
return foldername
def _generate_filename_debug(self, mm_hash: str) -> str:
def _generate_filename_debug(
self,
mm_hash: str,
create_folder: bool = True,
) -> str:
"""Return the full path of the safetensors file for this mm_hash.
Ensures the parent directory exists because
`_generate_foldername_debug` is called with its default
(`create_folder=True`).
If `create_folder` is True (default) the parent directory is created.
"""
foldername = self._generate_foldername_debug(mm_hash) # <- folder auto-created
foldername = self._generate_foldername_debug(mm_hash, create_folder)
return os.path.join(foldername, "encoder_cache.safetensors")