Reworked base

This commit is contained in:
9seconds
2019-08-29 13:16:08 +03:00
parent 09c7ce45d2
commit 07985cf418
26 changed files with 1481 additions and 271 deletions
+32
View File
@@ -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
}