Code Room
Code reviewMediumcr-g530
Subject Code reviewLevel Mid–Senior~20 minCommon in Concurrency interviewsIndustries Software development

Question

Review this Go in-memory cache. Two goroutines may call GetOrCompute for the same key concurrently.

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.

Talk through your review
Code to reviewgo
type Cache struct {	mu   sync.RWMutex	data map[string]int} func (c *Cache) GetOrCompute(key string, compute func() int) int {	c.mu.RLock()	v, ok := c.data[key]	c.mu.RUnlock()	if ok {		return v	}	val := compute()	c.mu.Lock()	c.data[key] = val	c.mu.Unlock()	return val}
Run or narrate your approach, then ask the coach.