Replace in-memory TTL cache with Redis
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi import APIRouter, HTTPException, Response
|
||||
|
||||
from models.schemas import DriveDetail
|
||||
from services.smart import get_smart_data
|
||||
@@ -8,10 +8,10 @@ router = APIRouter(prefix="/api/drives", tags=["drives"])
|
||||
|
||||
|
||||
@router.get("/{device}", response_model=DriveDetail)
|
||||
async def get_drive_detail(device: str):
|
||||
async def get_drive_detail(device: str, response: Response):
|
||||
"""Get SMART detail for a specific block device."""
|
||||
try:
|
||||
data = await get_smart_data(device)
|
||||
data, cache_hit = await get_smart_data(device)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
@@ -25,4 +25,6 @@ async def get_drive_detail(device: str):
|
||||
data["zfs_vdev"] = zfs_info["vdev"]
|
||||
data["zfs_state"] = zfs_info.get("state")
|
||||
|
||||
response.headers["X-Cache"] = "HIT" if cache_hit else "MISS"
|
||||
|
||||
return DriveDetail(**data)
|
||||
|
||||
Reference in New Issue
Block a user