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
+9
View File
@@ -256,6 +256,9 @@ importers:
escape-html:
specifier: ^1.0.3
version: 1.0.3
lru-cache:
specifier: ^11.3.2
version: 11.3.2
lucide-react:
specifier: ^0.577.0
version: 0.577.0([email protected])
@@ -9286,6 +9289,10 @@ packages:
resolution: {integrity: sha512-aY/R+aEsRelme17KGQa/1ZSIpLpNYYrhcrepKTZgE+W3WM16YMCaPwOHLHsmopZHELU0Ojin1lPVxKR0MihncA==}
engines: {node: 20 || >=22}
[email protected]:
resolution: {integrity: sha512-wgWa6FWQ3QRRJbIjbsldRJZxdxYngT/dO0I5Ynmlnin8qy7tC6xYzbcJjtN4wHLXtkbVwHzk0C+OejVw1XM+DQ==}
engines: {node: 20 || >=22}
[email protected]:
resolution: {integrity: sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==}
@@ -21867,6 +21874,8 @@ snapshots:
[email protected]: {}
[email protected]: {}
[email protected]:
dependencies:
yallist: 3.1.1