fix(login): replace custom SWR cache with lru-cache (#11945)

# Which Problems Are Solved

The in-memory SWR promiseCache in zitadel.ts used keys like
getBrandingSettings-${org} that had no instance identifier. In
multi-tenant mode, where a single Next.js process serves multiple
instances, an instance A's cached settings without org context
(branding, languages, settings, etc.) could be served to Instance B
request without org context. The cache now additionally is bound to 100
entries by default (configurable via maxSize in `API_CACHE_CONFIG`).
When capacity is exceeded, expired entries are swept first

It additionally replaces the hand-rolled PromiseCache (Map-based, FIFO
eviction) with lru-cache, leveraging its built-in fetchMethod for
stale-while-revalidate, request deduplication, and true LRU eviction.

# How the Problems Are Solved

Added an instanceCacheKey() helpe that prefixes every cache key with
serviceConfig.instanceHost in addition to the org context if available.

---------

Co-authored-by: Ramon <[email protected]>
This commit is contained in:
Max Peintner
2026-04-13 11:19:50 +02:00
committed by GitHub
co-authored by Ramon
parent 551883dcab
commit 7d231b43d4
6 changed files with 363 additions and 26 deletions
+1
View File
@@ -41,6 +41,7 @@
"copy-to-clipboard": "^3.3.3",
"deepmerge": "^4.3.1",
"escape-html": "^1.0.3",
"lru-cache": "^11.3.2",
"lucide-react": "^0.577.0",
"moment": "^2.30.1",
"next": "16.2.2",