37 lines
716 B
Go
37 lines
716 B
Go
package vo
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type CacheKey string
|
|
|
|
const (
|
|
WechatNotifyRegisterTagCacheKey CacheKey = "wechat_notify_register_tag"
|
|
WechatNotifyRegisterTagCacheLockKey CacheKey = "wechat_notify_register_tag_lock"
|
|
)
|
|
|
|
var CacheKeyMap = map[CacheKey]time.Duration{
|
|
WechatNotifyRegisterTagCacheKey: 86400 * time.Second,
|
|
WechatNotifyRegisterTagCacheLockKey: 30 * time.Second,
|
|
}
|
|
|
|
type Cache struct {
|
|
Key string
|
|
TTL time.Duration
|
|
}
|
|
|
|
func (s CacheKey) BuildCache(tag, stockCreatorMchID, stockID string) *Cache {
|
|
k := fmt.Sprintf("%s_%s_%s_%s", s, tag, stockCreatorMchID, stockID)
|
|
c := &Cache{
|
|
Key: k,
|
|
}
|
|
ttl, ok := CacheKeyMap[s]
|
|
if !ok {
|
|
c.TTL = 30 // 默认30秒
|
|
}
|
|
c.TTL = ttl
|
|
return c
|
|
}
|