2023-06-04 22:54:54 +08:00

37 lines
536 B
Go

package utils
import (
cache "github.com/patrickmn/go-cache"
"sync"
"time"
)
var lock sync.Mutex
var msgCache = cache.New(12*time.Hour, 12*time.Hour)
func PutCache(unionId, groupId string) {
lock.Lock()
defer lock.Unlock()
msgCache.Set(unionId, groupId, time.Hour*12)
}
func GetCache(unionId string) string {
lock.Lock()
defer lock.Unlock()
msg, found := msgCache.Get(unionId)
if found {
return msg.(string)
}
return ""
}
func Clear(unionId string) {
lock.Lock()
defer lock.Unlock()
msgCache.Delete(unionId)
}