From ea86194ce89b4f88e27f91a24046232334f0ff48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Stach?= Date: Fri, 9 Oct 2026 18:25:46 +0200 Subject: [PATCH] docs: add cache proposal for background renewal Co-authored-by: aider (openrouter/thinkingmachines/inkling-small:free) --- docs/cache-proposal.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 docs/cache-proposal.md diff --git a/docs/cache-proposal.md b/docs/cache-proposal.md new file mode 100644 index 0000000..fcc86ff --- /dev/null +++ b/docs/cache-proposal.md @@ -0,0 +1,39 @@ +# Cache Proposal for Kubectl Web GUI + +## Problem +With ~1600 pods, loading full lists from kubectl is slow. We need backend caching with background renewal so users are not blocked. + +## Ideas + +### 1. In-Memory TTL Cache with Background Refresh +- Store parsed item lists in a Python dict with 5-minute TTL. +- A background thread (threading.Timer or asyncio) refreshes each resource type every 4 minutes. +- Users always read from memory; refresh is invisible. + +### 2. Stale-While-Revalidate Pattern +- Serve cached data immediately. +- If cache is older than 3 minutes, trigger a background kubectl call to update it. +- User gets fast response; data updates shortly after. + +### 3. Per-Resource Background Workers +- One lightweight thread per resource (pods, nodes, pvcs, configmaps). +- Each thread runs kubectl on its own interval (e.g., 4 min). +- Cache is always warm; no user request triggers kubectl unless bypass is used. + +### 4. Cache Invalidation on Actions +- After delete/cordon/uncordon, invalidate only that resource's cache. +- Next load will refresh just that resource, not all. + +### 5. Partial / Chunked Cache +- Cache full list but paginate in backend. +- Background refresh updates the full list; pagination stays fast. + +## Background Renewal Approach +- Use threading.Thread with a loop and time.sleep(240) per resource. +- Or use FastAPI startup event to spawn refresh tasks. +- Ensure thread-safe access to the shared cache dict (GIL helps, but use locks if needed). + +## Trade-offs +- Memory usage: ~1600 pods is small; acceptable. +- Staleness: 4-5 minutes is okay for a local GUI. +- Refresh impact: background only, so app stays responsive.