Spaces:
Sleeping
Sleeping
Update document_generator_v2.py
Browse files- document_generator_v2.py +24 -0
document_generator_v2.py
CHANGED
|
@@ -166,6 +166,7 @@ import functools
|
|
| 166 |
from fastapi import APIRouter, HTTPException, Request, UploadFile, File, Depends
|
| 167 |
from fastapi.responses import StreamingResponse
|
| 168 |
from pydantic import BaseModel
|
|
|
|
| 169 |
from fastapi_cache.decorator import cache
|
| 170 |
import psycopg2
|
| 171 |
from datetime import datetime
|
|
@@ -638,4 +639,27 @@ async def get_last_observations(limit: int = 10, format: str = "json"):
|
|
| 638 |
except Exception as e:
|
| 639 |
raise HTTPException(status_code=500, detail=f"Failed to retrieve observations: {str(e)}")
|
| 640 |
|
|
|
|
| 641 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
from fastapi import APIRouter, HTTPException, Request, UploadFile, File, Depends
|
| 167 |
from fastapi.responses import StreamingResponse
|
| 168 |
from pydantic import BaseModel
|
| 169 |
+
from fastapi_cache import FastAPICache
|
| 170 |
from fastapi_cache.decorator import cache
|
| 171 |
import psycopg2
|
| 172 |
from datetime import datetime
|
|
|
|
| 639 |
except Exception as e:
|
| 640 |
raise HTTPException(status_code=500, detail=f"Failed to retrieve observations: {str(e)}")
|
| 641 |
|
| 642 |
+
## TEST CACHE
|
| 643 |
|
| 644 |
+
class CacheItem(BaseModel):
|
| 645 |
+
key: str
|
| 646 |
+
value: str
|
| 647 |
+
|
| 648 |
+
@router.post("/set-cache")
|
| 649 |
+
async def set_cache(item: CacheItem):
|
| 650 |
+
try:
|
| 651 |
+
# Set the cache with a default expiration of 1 hour (3600 seconds)
|
| 652 |
+
await FastAPICache.set(item.key, item.value, expire=3600)
|
| 653 |
+
return {"message": f"Cache set for key: {item.key}"}
|
| 654 |
+
except Exception as e:
|
| 655 |
+
raise HTTPException(status_code=500, detail=f"Failed to set cache: {str(e)}")
|
| 656 |
+
|
| 657 |
+
@router.get("/get-cache/{key}")
|
| 658 |
+
async def get_cache(key: str):
|
| 659 |
+
try:
|
| 660 |
+
value = await FastAPICache.get(key)
|
| 661 |
+
if value is None:
|
| 662 |
+
raise HTTPException(status_code=404, detail=f"No cache found for key: {key}")
|
| 663 |
+
return {"key": key, "value": value}
|
| 664 |
+
except Exception as e:
|
| 665 |
+
raise HTTPException(status_code=500, detail=f"Failed to get cache: {str(e)}")
|