You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
paopao-ce/internal/metrics/statistics/cache.go

39 lines
846 B

// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package statistics
import (
"sync"
"github.com/rocboss/paopao-ce/internal/core"
)
var (
_metricCache core.MetricCache
_onceMetricCache sync.Once
)
type metricCache struct {
eventTempWorkerCount map[string]int
}
func (m *metricCache) SetEventTempWorkerCount(name string, count int) {
// 直接赋值,不需要加锁,因为这仅仅是一个统计信息
m.eventTempWorkerCount[name] = count
}
func (m *metricCache) GetEventTempWorkerCount(name string) int {
return m.eventTempWorkerCount[name]
}
func NewMetricCache() core.MetricCache {
_onceMetricCache.Do(func() {
_metricCache = &metricCache{
eventTempWorkerCount: make(map[string]int),
}
})
return _metricCache
}