Code RoomCache serves stale user
HardPrep Room Coding #2163

Cache serves stale user

Code reviewDistributed systemsSenior–Staff~20 min

Review this read-through / write-through cache wrapper around a user store.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1def get_user(uid):
2 u = cache.get(uid)
3 if u is None:
4 u = db.fetch_user(uid)
5 cache.set(uid, u, ttl=3600)
6 return u
7 
8def update_user(uid, **fields):
9 db.update_user(uid, **fields)
10 cache.set(uid, db.fetch_user(uid), ttl=3600)
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.