1
0
mirror of https://github.com/ltcptgeneral/cs239-caching.git synced 2025-08-14 05:10:20 +00:00

Fixed POST requests in system

This commit is contained in:
Derek Wang
2025-03-03 19:28:15 -08:00
parent 8430009f8c
commit 32ac22806c
4 changed files with 40 additions and 11 deletions

@ -8,6 +8,7 @@ from cache.nocache import NoCache
from cache.idealcache import IdealCache
from cache.read_after_write_cache import ReadAfterWriteCache
from config import CACHE_STRATEGY, CACHE_LIMIT, L2_CACHE_LIMIT
from models.models import User
import time
app = FastAPI()
@ -62,8 +63,11 @@ def fetch_user_profile(user_id: str):
return {"user_id": user_id, "profile": profile, "source": "database", "time_ms": (time.time() - start) * 1000}
@app.post("/update_user/")
def modify_user_profile(user_id: str, name: str, followers: int, bio: str, posts: str, friends: list[str]):
async def modify_user_profile(user_data : User):
"""Update user profile and refresh cache"""
update_user_profile(user_id, name, followers, bio, posts, friends)
user_id=user_data.user_id
user_dict = user_data.dict()
update_user_profile(user_dict)
cache.invalidate(user_id) # Invalidate old cache
return {"message": "User profile updated successfully"}