24 lines
800 B
Python
24 lines
800 B
Python
from fastapi import APIRouter, HTTPException, Header
|
|
from typing import Optional
|
|
from app.config import API_KEY
|
|
from app.services.cache import clear_cache, get_cache_stats
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/cache/clear")
|
|
async def clear_cache_route(x_api_key: Optional[str] = Header(None)):
|
|
"""Clear the entire cache database"""
|
|
# Validate API key
|
|
if not x_api_key or x_api_key != API_KEY:
|
|
raise HTTPException(status_code=401, detail="Invalid API key")
|
|
|
|
return clear_cache()
|
|
|
|
@router.get("/cache/stats")
|
|
async def cache_stats_route(x_api_key: Optional[str] = Header(None)):
|
|
"""Get cache statistics"""
|
|
# Validate API key
|
|
if not x_api_key or x_api_key != API_KEY:
|
|
raise HTTPException(status_code=401, detail="Invalid API key")
|
|
|
|
return get_cache_stats() |