The cache hands the person who filtered by one city the list somebody else asked for.
Context, code, logs and metrics, the same material you would have in production, with nobody pointing at the problem.
No multiple choice and no single right answer: you write what you think is happening, what you would do and what it costs.
The moment you submit, the written solution opens next to your answers, and stays open for you to reread whenever you want.
The jobs-api serves the job search on the site. The URL accepts ?city=, ?level= and ?page=, and since the query takes about 300ms, somebody put a five minute cache in front of it.
const cache = new Map<string, { expiresAt: number; body: JobsPage }>();
export async function listJobs(req: Request, res: Response) {
const page = Number(req.query.page ?? 1);
const key = `jobs:page:${page}`;
const cached = cache.get(key);
if (cached && cached.expiresAt > Date.now()) {
return res.json(cached.body);
}
const body = await searchJobs({
city: req.query.city,
level: req.query.level,
page,
});
cache.set(key, { expiresAt: Date.now() + 5 * 60 * 1000, body });
return res.json(body);
}Locked
Opening a challenge costs 1 credit. A new account starts with 3, no card.