fixed cache exclude path + test added

This commit is contained in:
2026-10-21 00:03:27 +02:00
parent 7e4497e01b
commit 5a51715b05
2 changed files with 31 additions and 2 deletions
@@ -17,7 +17,7 @@ NO_STORE_PATH_PREFIXES = (
"/api/bookmarks",
"/api/organizations",
"/api/orgminer/get-hierarchy",
"api/orgminer/hierarchy-suggestions",
"/api/orgminer/hierarchy-suggestions",
)
# Keep these responses in the server-side ETag cache, but require the browser
@@ -7,7 +7,14 @@ from inse.middleware.etag_cache import ETagCacheMiddleware
def _app_with_counter():
app = FastAPI()
calls = {"get": 0, "post": 0, "dashboard": 0, "read_only": 0, "hierarchy": 0}
calls = {
"get": 0,
"post": 0,
"dashboard": 0,
"read_only": 0,
"hierarchy": 0,
"suggestions": 0,
}
@app.get("/api/background-jobs/tasks")
def get_tasks():
@@ -29,6 +36,11 @@ def _app_with_counter():
calls["hierarchy"] += 1
return {"call": calls["hierarchy"]}
@app.get("/api/orgminer/hierarchy-suggestions")
def get_hierarchy_suggestions():
calls["suggestions"] += 1
return {"call": calls["suggestions"]}
def read_only_response():
calls["read_only"] += 1
return {"call": calls["read_only"]}
@@ -106,6 +118,23 @@ def test_hierarchy_gets_are_never_cached_after_updates():
assert calls["hierarchy"] == 2
def test_hierarchy_suggestions_are_never_cached_after_review():
app, calls = _app_with_counter()
with TestClient(app) as client:
first = client.get("/api/orgminer/hierarchy-suggestions")
second = client.get(
"/api/orgminer/hierarchy-suggestions",
headers={"If-None-Match": first.headers.get("etag", "")},
)
assert first.status_code == 200
assert second.status_code == 200
assert first.headers["cache-control"] == "private, no-store, max-age=0"
assert second.json() == {"call": 2}
assert calls["suggestions"] == 2
def test_dashboard_revalidates_and_uses_a_separate_cache_for_a_new_token():
app, calls = _app_with_counter()