FILE / ScuroNeko/mtg

newantireplay/cache.go

Исходный файл и его история в репозитории.
FILE 07985cf418c3b6d7e0b59de2d29e7e927bedf401
Files
mtg/newantireplay/cache.go
T
2019-08-29 13:16:08 +03:00

33 lines
556 B
Go

package newantireplay
import (
"github.com/allegro/bigcache"
"github.com/9seconds/mtg/newconfig"
)
var cache *bigcache.BigCache
func Add(data []byte) {
cache.Set(string(data), nil)
}
func Has(data []byte) bool {
_, err := cache.Get(string(data))
return err == nil
}
func Init() {
c, err := bigcache.NewBigCache(bigcache.Config{
Shards: 1024,
LifeWindow: newconfig.C.AntiReplay.EvictionTime,
Hasher: hasher{},
HardMaxCacheSize: newconfig.C.AntiReplay.MaxSize,
})
if err != nil {
panic(err)
}
cache = c
}