mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 14:04:02 +03:00
Rework antireplay
This commit is contained in:
@@ -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,
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user