cache_medal.go 486 Bytes
Newer Older
chenweijian's avatar
chenweijian committed
1 2 3
package common

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

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

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

iamhujiebin's avatar
iamhujiebin committed
19 20
func SetUserMedalMergeCache(userId mysql.ID, data []uint32) {
	_ = userMedalMergeLru.SetWithExpire(userId, data, time.Minute*15)
chenweijian's avatar
chenweijian committed
21
}