FILE / ScuroNeko/mtg

antireplay/cache.go

Исходный файл и его история в репозитории.
FILE 2492a47d0ac343df5714bdb024261ed912d3eda4
Files
mtg/antireplay/cache.go
T
2019-09-04 10:19:01 +03:00

31 lines
549 B
Go

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