Rework antireplay

This commit is contained in:
9seconds
2019-10-07 17:51:21 +03:00
parent 413cafeeb6
commit d44474012a
3 changed files with 42 additions and 26 deletions
+31
View File
@@ -0,0 +1,31 @@
package antireplay
import (
"sync"
"github.com/9seconds/mtg/config"
"github.com/allegro/bigcache"
)
var (
Cache *cache
initOnce sync.Once
)
func Init() {
initOnce.Do(func() {
c, err := bigcache.NewBigCache(bigcache.Config{
Shards: 1024,
LifeWindow: config.C.AntiReplay.EvictionTime,
Hasher: hasher{},
HardMaxCacheSize: config.C.AntiReplay.MaxSize,
})
if err != nil {
panic(err)
}
Cache = &cache{
cache: c,
}
})
}