package pkg
import (
"github.com/dgraph-io/ristretto"
"log"
"sync"
"time"
)
var onceCache sync.Once
var Cache *ristretto.Cache
func init() {
onceCache.Do(func() {
Cache = Caches()
})
}
func Caches() *ristretto.Cache {
cache, err := ristretto.NewCache(&ristretto.Config{
NumCounters: 1e7, // Num keys to track frequency of (10M).
MaxCost: 1 << 30, // Maximum cost of cache (1GB).
BufferItems: 64, // Number of keys per Get buffer.
IgnoreInternalCost :true,
})
if err != nil {
panic(any(err))
}
return cache
}
func txst() {
kv :="值"
Cache.SetWithTTL("k", kv, 1, time.Second*1800)
Cache.Wait()
v, ok := Cache.Get("k")
if !ok {
return
}else {
log.Println(v)
}
}