Skip to content

Commit 5fa71fd

Browse files
committed
fix
1 parent f985ed6 commit 5fa71fd

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

app/server.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import asyncpg
77
from dotenv import load_dotenv
88
from fastapi import Depends, FastAPI, HTTPException, Query
9+
from fastapi.middleware.gzip import GZipMiddleware
10+
from fastapi_cache import FastAPICache
11+
from fastapi_cache.backends.inmemory import InMemoryBackend
12+
from fastapi_cache.decorator import cache
913

1014
load_dotenv()
1115

@@ -18,10 +22,12 @@ async def lifespan(app: FastAPI):
1822
min_size=5,
1923
max_size=20
2024
)
25+
FastAPICache.init(InMemoryBackend())
2126
yield
2227
await app.state.pool.close()
2328

2429
app = FastAPI(lifespan=lifespan)
30+
app.add_middleware(GZipMiddleware, minimum_size=1000)
2531

2632
async def get_db():
2733
async with app.state.pool.acquire() as conn:
@@ -34,6 +40,7 @@ async def index():
3440

3541

3642
@app.get("/visits")
43+
@cache(expire=300)
3744
async def get_visits(
3845
begin: str = Query(..., description="Start date in ISO format"),
3946
end: str = Query(..., description="End date in ISO format"),
@@ -57,6 +64,7 @@ async def get_visits(
5764
)
5865

5966
@app.get("/registrations")
67+
@cache(expire=300)
6068
async def get_registrations(
6169
begin: str = Query(..., description="Start date in ISO format"),
6270
end: str = Query(..., description="End date in ISO format"),

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ readme = "README.md"
66
requires-python = ">=3.12"
77
dependencies = [
88
"asyncpg>=0.30.0",
9+
"fastapi-cache2>=0.2.2",
910
"fastapi[standard]>=0.115.4",
1011
"flask>=3.0.3",
1112
"psycopg[binary]>=3.2.3",

uv.lock

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)