mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 07:34:01 +03:00
Reworked base
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package newantireplay
|
||||
|
||||
import "github.com/cespare/xxhash"
|
||||
|
||||
type hasher struct{}
|
||||
|
||||
func (h hasher) Sum64(value string) uint64 {
|
||||
return xxhash.Sum64String(value)
|
||||
}
|
||||
Reference in New Issue
Block a user