1 function cacheKeyForReport(reportId) {
2 return 'report:' + reportId;
3 }
4
5 async function getReport(user, reportId) {
6 const key = cacheKeyForReport(reportId);
7 const hit = await redis.get(key);
8 if (hit) return JSON.parse(hit);
9
10 const report = await db.reports.findOne({ id: reportId, tenantId: user.tenantId });
11 await redis.set(key, JSON.stringify(report), 'EX', 600);
12 return report;
13 }
no lines flagged clear
#115 Practice Medium 16 min · 120 XP
Cache Key Omits the Tenant Scope A multi-tenant reporting page intermittently shows one company data that belongs to a different company. It is never reproducible in staging, which has a single tenant.
Flagged lines No lines flagged yet
Submit answer Flag a line or write a note to submit.