Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions gs/backend/api/lifespan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from contextlib import asynccontextmanager

from fastapi import FastAPI
from fastapi_cache import FastAPICache
from fastapi_cache.backends.inmemory import InMemoryBackend

from gs.backend.data.database.engine import get_db_session, setup_database
from gs.backend.data.resources.utils import add_main_commands
Expand All @@ -10,6 +12,9 @@
@asynccontextmanager
async def lifespan(_: FastAPI) -> AsyncGenerator[None, None]:
"""Lifecycle event for the FastAPI app."""
# Initialize FastAPI Cache (in memory cache)
FastAPICache.init(InMemoryBackend())

# Must all the get_db_session each time when pass it into a separate function.
# Otherwise, will get transaction is inactive error
setup_database(get_db_session())
Expand Down
2 changes: 2 additions & 0 deletions gs/backend/api/v1/mcc/endpoints/main_commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fastapi import APIRouter
from fastapi_cache.decorator import cache

from gs.backend.api.v1.mcc.models.responses import MainCommandsResponse
from gs.backend.data.data_wrappers.mcc_wrappers.main_command_wrapper import get_all_main_commands
Expand All @@ -7,6 +8,7 @@


@main_commands_router.get("/")
@cache(expire=300) # Cache for 5 minutes
async def get_main_commands() -> MainCommandsResponse:
"""
Gets the main commands that are available for the MCC
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ requests==2.31.0
pyserial==3.5
skyfield==1.48
fastapi[standard]==0.115.0
fastapi-cache2==0.2.1
sqlmodel==0.0.22
jinja2==3.1.6
toml==0.10.2
Expand Down
Loading