// 汇总信息 func (this *MemberC) Summary(ctx *echo.Context) error { memberId := GetMemberId(ctx) var updateTime int64 = dps.MemberService.GetMemberLatestUpdateTime(memberId) var v *dto.MemberSummary = new(dto.MemberSummary) var key = fmt.Sprintf("cac:mm:summary:%d", memberId) if cache.GetKVS().Get(key, &v) != nil || v.UpdateTime < updateTime { v = dps.MemberService.GetMemberSummary(memberId) cache.GetKVS().SetExpire(key, v, 3600*48) // cache 48 hours } return ctx.JSON(http.StatusOK, v) }
func getMemberAccount(memberId int, updateTime int) *member.Account { sto := gof.CurrentApp.Storage() var kvAut int autKey := fmt.Sprintf("%s%d", variable.KvAccountUpdateTime, memberId) kvAut, _ = sto.GetInt(autKey) //get from redis var v *member.Account = new(member.Account) var key = fmt.Sprintf("cac:mm:acc:%d", memberId) if kvAut != 0 && kvAut == updateTime { if cache.GetKVS().Get(key, v) == nil { return v } } v = dps.MemberService.GetAccount(memberId) sto.SetExpire(key, v, 3600*360) // cache 15 hours sto.SetExpire(autKey, v.UpdateTime, 3600*400) return v }
// get summary of member,if dbGet will get summary from database. func GetMemberSummary(memberId int, updateTime int) *dto.MemberSummary { sto := gof.CurrentApp.Storage() var kvMut int mutKey := fmt.Sprintf("%s%d", variable.KvMemberUpdateTime, memberId) kvMut, _ = sto.GetInt(mutKey) //get from redis var v *dto.MemberSummary = new(dto.MemberSummary) var key = fmt.Sprintf("cac:mm:summary:%d", memberId) if kvMut != 0 && kvMut == updateTime { if cache.GetKVS().Get(key, v) == nil { return v } } v = dps.MemberService.GetMemberSummary(memberId) if v != nil { sto.SetExpire(key, v, 3600*360) // cache 15 hours sto.SetExpire(mutKey, v.UpdateTime, 3600*400) } else { println("---", v, memberId, "-----") } return v }