cache_medal.go 804 Bytes
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5
package common

import (
	"git.hilo.cn/hilo-common/resource/mysql"
	"git.hilo.cn/hilo-common/utils"
iamhujiebin's avatar
iamhujiebin committed
6
	"github.com/bluele/gcache"
hujiebin's avatar
hujiebin committed
7 8 9
	"time"
)

iamhujiebin's avatar
iamhujiebin committed
10 11
// 改成lru
var userMedalMergeLru = gcache.New(10000).LRU().Build()
hujiebin's avatar
hujiebin committed
12

iamhujiebin's avatar
iamhujiebin committed
13 14 15
func GetUserMedalMergeCache(userId mysql.ID) ([]uint32, error) {
	if data, err := userMedalMergeLru.Get(userId); err == nil {
		return data.([]uint32), nil
hujiebin's avatar
hujiebin committed
16
	}
iamhujiebin's avatar
iamhujiebin committed
17
	return nil, nil
hujiebin's avatar
hujiebin committed
18 19
}

iamhujiebin's avatar
iamhujiebin committed
20 21
func SetUserMedalMergeCache(userId mysql.ID, data []uint32) {
	_ = userMedalMergeLru.SetWithExpire(userId, data, time.Minute*15)
hujiebin's avatar
hujiebin committed
22 23 24 25 26 27 28 29 30 31 32
}

// 删除勋章缓存, 延迟删除
func DelUserMedalMergeCacheDelay(userId mysql.ID) {
	go func() {
		defer utils.CheckGoPanic()
		time.Sleep(time.Second * 5)
		DelUserMedalMergeCache(userId)
	}()
}

iamhujiebin's avatar
iamhujiebin committed
33 34
func DelUserMedalMergeCache(userId mysql.ID) {
	userMedalMergeLru.Remove(userId)
hujiebin's avatar
hujiebin committed
35
}