Problem Statement
How do you keep caches safe in multi-tenant systems?
Explanation
Namespace keys by tenant and enforce auth at the edge so private responses do not leak to shared caches. Use Vary headers to separate cached variants by auth token or role when using CDNs. Encrypt sensitive payloads at rest in the cache and avoid caching personal data unless necessary. Add strict cache-busting rules on logout or permission changes.
Code Solution
SolutionRead Only
key = tenantId + ":user:" + userId + ":profile:v2"
