From bc7e74f28d59b20fec2fe7d1550944a4e3cf14c4 Mon Sep 17 00:00:00 2001
From: lilly
Date: Thu, 7 May 2026 21:38:22 +0200
Subject: [PATCH] api: add tooling for keeping a local cache
---
api/pyproject.toml | 1 +
api/src/dooris_api/app.py | 3 +++
api/src/dooris_api/deps.py | 7 +++++++
api/uv.lock | 11 +++++++++++
4 files changed, 22 insertions(+)
diff --git a/api/pyproject.toml b/api/pyproject.toml
index 02e647d..e86f301 100644
--- a/api/pyproject.toml
+++ b/api/pyproject.toml
@@ -4,6 +4,7 @@ version = "0.1.0"
description = "API for Dooris setup using HomeMatic."
requires-python = ">=3.13"
dependencies = [
+ "cachetools>=7.1.1",
"fastapi>=0.136.1",
"simple-openid-connect>=2.4.0",
"uvicorn>=0.46.0",
diff --git a/api/src/dooris_api/app.py b/api/src/dooris_api/app.py
index 43922b3..90ff347 100644
--- a/api/src/dooris_api/app.py
+++ b/api/src/dooris_api/app.py
@@ -30,6 +30,9 @@ async def lifespan(app: FastAPI):
client_id="dooris",
client_secret="dp9HhnvUhAtKm3pRnxfGA7q8Nwrd1td8",
)
+
+ app.extra["cache"] = TTLCache(maxsize=64, ttl=30 * 60)
+
yield
diff --git a/api/src/dooris_api/deps.py b/api/src/dooris_api/deps.py
index 9251bfd..7621298 100644
--- a/api/src/dooris_api/deps.py
+++ b/api/src/dooris_api/deps.py
@@ -69,3 +69,10 @@ def persist_auth_state(oidc_client: OpenidClient, resp: Response, tokens: TokenS
CurrentUser = Annotated[Optional[models.CurrentUser], Depends(get_current_user)]
+
+def get_cache(req: Request) -> Cache:
+ return req.app.extra["cache"]
+
+
+Cache = Annotated[Cache, Depends(get_cache)]
+
diff --git a/api/uv.lock b/api/uv.lock
index 7da2bd9..61f1678 100644
--- a/api/uv.lock
+++ b/api/uv.lock
@@ -41,6 +41,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/d2/39/e7eaf1799466a4aef85b6a4fe7bd175ad2b1c6345066aa33f1f58d4b18d0/asttokens-3.0.1-py3-none-any.whl", hash = "sha256:15a3ebc0f43c2d0a50eeafea25e19046c68398e487b9f1f5b517f7c0f40f976a", size = 27047, upload-time = "2025-11-15T16:43:16.109Z" },
]
+[[package]]
+name = "cachetools"
+version = "7.1.1"
+source = { registry = "https://pypi.org/simple" }
+sdist = { url = "https://files.pythonhosted.org/packages/ff/e2/85f227594656000ff4d8adadae91a21f536d4a84c6c716a86bd6685874be/cachetools-7.1.1.tar.gz", hash = "sha256:27bdf856d68fd3c71c26c01b5edc312124ed427524d1ddb31aa2b7746fe20d4b", size = 40202, upload-time = "2026-05-03T20:00:29.391Z" }
+wheels = [
+ { url = "https://files.pythonhosted.org/packages/bf/0f/f897abe4ea0a8c408ae65c8c83bffab4936ad65d6032d4fb4cd35bbdc3ee/cachetools-7.1.1-py3-none-any.whl", hash = "sha256:0335cd7a0952d2b22327441fb0628139e234c565559eeb91a8a4ac7551c5353d", size = 16775, upload-time = "2026-05-03T20:00:27.857Z" },
+]
+
[[package]]
name = "certifi"
version = "2026.4.22"
@@ -253,6 +262,7 @@ name = "dooris-api"
version = "0.1.0"
source = { editable = "." }
dependencies = [
+ { name = "cachetools" },
{ name = "fastapi" },
{ name = "simple-openid-connect" },
{ name = "uvicorn" },
@@ -265,6 +275,7 @@ dev = [
[package.metadata]
requires-dist = [
+ { name = "cachetools", specifier = ">=7.1.1" },
{ name = "fastapi", specifier = ">=0.136.1" },
{ name = "simple-openid-connect", specifier = ">=2.4.0" },
{ name = "uvicorn", specifier = ">=0.46.0" },