I have 2 different endpoints
from fastapi import APIRouter
router = APIRouter()
@router.get("/endpoint_1")
async def endpoint_1(attributes):
interim_data = await get_interim_data() # performs heavy search
result = process_data_1(interim_data)
return result
@router.get("/endpoint_2")
async def endpoint_2():
interim_data = await get_interim_data() # performs heavy search
result = process_data_2(interim_data)
return result
Both endpoints call the same function to get initial data but further usage of that data is different. If requests to endpoint_1
and endpoint_2
are created at the same time, how can I make it so that get_interim_data
would only be called once?