(feat) support cache flush on redis

This commit is contained in:
Ishaan Jaff 2024-03-26 09:12:30 -07:00
parent ade5d58331
commit 151b717ae2

View file

@ -7753,6 +7753,37 @@ async def cache_ping():
) )
@router.post(
"/cache/flush",
tags=["caching"],
dependencies=[Depends(user_api_key_auth)],
)
async def cache_flush():
"""
Endpoint for checking if cache can be pinged
"""
try:
if litellm.cache is None:
raise HTTPException(
status_code=503, detail="Cache not initialized. litellm.cache is None"
)
if litellm.cache.type == "redis":
litellm.cache.cache.flushall()
return {
"status": "success",
}
else:
raise HTTPException(
status_code=500,
detail=f"Cache type {litellm.cache.type} does not support flushing",
)
except Exception as e:
raise HTTPException(
status_code=503,
detail=f"Service Unhealthy ({str(e)})",
)
@router.get("/", dependencies=[Depends(user_api_key_auth)]) @router.get("/", dependencies=[Depends(user_api_key_auth)])
async def home(request: Request): async def home(request: Request):
return "LiteLLM: RUNNING" return "LiteLLM: RUNNING"