mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 12:54:01 +03:00
FILE / ScuroNeko/mtg
antireplay/init.go
Исходный файл и его история в репозитории.
35 lines
494 B
Go
35 lines
494 B
Go
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
|
|
})
|
|
}
|