[HiCache] fix: check clear() method for storage backend (#10096)
Co-authored-by: hzh0425 <hzh0425@apache.org>
This commit is contained in:
@@ -134,11 +134,24 @@ class HiRadixCache(RadixCache):
|
||||
height += 1
|
||||
return height
|
||||
|
||||
def clear_storage_backend(self):
|
||||
def clear_storage_backend(self) -> bool:
|
||||
if self.enable_storage:
|
||||
self.cache_controller.storage_backend.clear()
|
||||
logger.info("Hierarchical cache storage backend cleared successfully!")
|
||||
return True
|
||||
try:
|
||||
# Check if the storage backend has a clear method (for nixl backends)
|
||||
if hasattr(self.cache_controller.storage_backend, "clear"):
|
||||
self.cache_controller.storage_backend.clear()
|
||||
logger.info(
|
||||
"Hierarchical cache storage backend cleared successfully!"
|
||||
)
|
||||
return True
|
||||
else:
|
||||
logger.warning(
|
||||
f"Storage backend {type(self.cache_controller.storage_backend).__name__} does not support clear operation."
|
||||
)
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to clear hierarchical cache storage backend: {e}")
|
||||
return False
|
||||
else:
|
||||
logger.warning("Hierarchical cache storage backend is not enabled.")
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user