| 12345678910111213141516171819202122232425262728293031323334 |
- package antireplay
-
- import (
- "math"
- "sync"
-
- "github.com/dgraph-io/ristretto"
-
- "mtg/config"
- )
-
- var (
- Cache cache
- initOnce sync.Once
- )
-
- func Init() {
- initOnce.Do(func() {
- cost := float64(config.C.AntiReplayMaxSize) / 32.0
- cost = math.Ceil(cost)
-
- c, err := ristretto.NewCache(&ristretto.Config{
- NumCounters: int64(cost) * 10,
- MaxCost: config.C.AntiReplayMaxSize,
- BufferItems: 64,
- Metrics: false,
- })
- if err != nil {
- panic(err)
- }
-
- Cache.data = c
- })
- }
|