in internal/alloydb/instance.go [189:219]
func NewRefreshAheadCache(
instance InstanceURI,
l debug.ContextLogger,
client *alloydbadmin.AlloyDBAdminClient,
key *rsa.PrivateKey,
refreshTimeout time.Duration,
dialerID string,
disableMetadataExchange bool,
userAgent string,
mr telv2.MetricRecorder,
) *RefreshAheadCache {
ctx, cancel := context.WithCancel(context.Background())
i := &RefreshAheadCache{
instanceURI: instance,
logger: l,
l: rate.NewLimiter(rate.Every(refreshInterval), refreshBurst),
r: newAdminAPIClient(client, key, dialerID, disableMetadataExchange),
refreshTimeout: refreshTimeout,
ctx: ctx,
cancel: cancel,
userAgent: userAgent,
metricRecorder: mr,
}
// For the initial refresh operation, set cur = next so that connection
// requests block until the first refresh is complete.
i.resultGuard.Lock()
i.cur = i.scheduleRefresh(0)
i.next = i.cur
i.resultGuard.Unlock()
return i
}