37
}
38
40
>
return &sharedScopeCache{
41
>
maxSize: maxSize,
42
>
scopes: make(map[string]tally.Scope),
43
>
handlers: make(map[string]*tallyMetricsHandler),
44
>
}
45
>
}
46
47
>
func (c *sharedScopeCache) loadOrStoreScope(key string, create func() tally.Scope) tally.Scope {
tally_metrics_handler.go
48
>
c.mu.RLock()
49
>
if s, ok := c.scopes[key]; ok {
50
c.mu.RUnlock()
51
return s
52
}
54
>
55
>
s := create()
56
>
57
>
c.mu.Lock()
58
>
defer c.mu.Unlock()
59
>
// Double-check: another goroutine may have inserted while we were creating.
60
>
if existing, ok := c.scopes[key]; ok {
61
return existing
62
}
65
>
}
67
>
return s
68
}
69