serverctl/services/entry/pkg/infrastructure/dependencies/cache.go

30 lines
671 B
Go
Raw Normal View History

2022-02-16 16:27:48 +01:00
package dependencies
import (
"github.com/dgraph-io/ristretto"
"github.com/eko/gocache/cache"
"github.com/eko/gocache/metrics"
"github.com/eko/gocache/store"
"go.uber.org/zap"
)
func setupCache(l *zap.Logger) *cache.MetricCache {
l.Info("Setting up Cache")
ristrettoCache, err := ristretto.NewCache(&ristretto.Config{
NumCounters: 1000,
MaxCost: 100_000_000,
BufferItems: 64,
})
promMetrics := metrics.NewPrometheus("serverctl")
if err != nil {
panic(err)
}
ristrettoStore := store.NewRistretto(ristrettoCache, nil)
cacheManager := cache.New(ristrettoStore)
metricsCache := cache.NewMetric(promMetrics, cacheManager)
return metricsCache
}