package vo import ( "time" "voucher/internal/pkg/helper" ) type CacheKey string const ( CmbOrderLockKey CacheKey = "cmb_order" CmbQueryLockKey CacheKey = "cmb_query" CmbProductQueryLockKey CacheKey = "cmb_product_query" OrderConsume CacheKey = "order_consume" NotifyConsume CacheKey = "notify_consume" NotifyRetryConsume CacheKey = "notify_retry_consume" WechatNotifyRegisterTagCacheKey CacheKey = "wechat_notify_register_tag" WechatNotifyRegisterTagCacheLockKey CacheKey = "wechat_notify_register_tag_lock" WechatNotifyConsumeLockKey CacheKey = "wechat_notify_consume" ) var CacheKeyMap = map[CacheKey]time.Duration{ CmbOrderLockKey: 30 * time.Second, CmbQueryLockKey: 30 * time.Second, CmbProductQueryLockKey: 30 * time.Second, OrderConsume: 60 * time.Second, NotifyConsume: 60 * time.Second, NotifyRetryConsume: 60 * time.Second, WechatNotifyRegisterTagCacheKey: 86400 * time.Second, WechatNotifyRegisterTagCacheLockKey: 30 * time.Second, WechatNotifyConsumeLockKey: 30 * time.Second, } type Cache struct { Key string TTL time.Duration } func (s CacheKey) GetValue() string { return string(s) } func (s CacheKey) BuildCache(strArr []string) *Cache { k := helper.BuildStr(s.GetValue(), strArr) c := &Cache{ Key: k, } ttl, ok := CacheKeyMap[s] if !ok { c.TTL = 30 // 默认30秒 } c.TTL = ttl return c } func (s CacheKey) BuildCacheUint64(ids []uint64) *Cache { k := helper.BuildStr(s.GetValue(), ids) c := &Cache{ Key: k, } ttl, ok := CacheKeyMap[s] if !ok { c.TTL = 30 // 默认30秒 } c.TTL = ttl return c }