feat(map): add cached public station navigation

This commit is contained in:
lingniu
2026-08-12 10:50:06 +08:00
parent 357dd490e9
commit 6ef98d03c2
13 changed files with 780 additions and 4 deletions
+12
View File
@@ -47,5 +47,17 @@ class DashboardTest(unittest.TestCase):
index_template = (Path(__file__).parents[1] / "index.html").read_text(encoding="utf-8")
self.assertEqual(index_template.count("__ASSET_VERSION__"), 2)
def test_default_cache_window_is_two_minutes(self):
self.assertEqual(server.DASHBOARD_CACHE_SECONDS, 120)
self.assertEqual(server.STATION_CACHE_SECONDS, 120)
def test_cache_reuses_dashboard_snapshot_within_window(self):
calls = []
with patch.object(server, "_cache", {}):
first = server._cached("dashboard", 120, lambda: calls.append("load") or {"version": 1})
second = server._cached("dashboard", 120, lambda: calls.append("load") or {"version": 2})
self.assertEqual(calls, ["load"])
self.assertEqual(first, second)
if __name__ == "__main__":
unittest.main()