123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- package archive
- import (
- "context"
- "fmt"
- arcMdl "go-common/app/interface/main/creative/model/archive"
- "go-common/library/cache/memcache"
- "go-common/library/log"
- "go-common/library/stat/prom"
- )
- var _ _mc
- func (d *Dao) CacheStaffData(c context.Context, id int64) (res []*arcMdl.Staff, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := staffKey(id)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheStaffData")
- log.Errorv(c, log.KV("CacheStaffData", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = []*arcMdl.Staff{}
- err = conn.Scan(reply, &res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheStaffData")
- log.Errorv(c, log.KV("CacheStaffData", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- func (d *Dao) AddCacheStaffData(c context.Context, id int64, val []*arcMdl.Staff) (err error) {
- if len(val) == 0 {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := staffKey(id)
- item := &memcache.Item{Key: key, Object: val, Expiration: 3, Flags: memcache.FlagJSON | memcache.FlagGzip}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheStaffData")
- log.Errorv(c, log.KV("AddCacheStaffData", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- func (d *Dao) DelCacheStaffData(c context.Context, id int64) (err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := staffKey(id)
- if err = conn.Delete(key); err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:DelCacheStaffData")
- log.Errorv(c, log.KV("DelCacheStaffData", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- func (d *Dao) AddCacheViewPoint(c context.Context, id int64, val *arcMdl.ViewPointRow, cid int64) (err error) {
- if val == nil {
- return
- }
- conn := d.mc.Get(c)
- defer conn.Close()
- key := viewPointCacheKey(id, cid)
- item := &memcache.Item{Key: key, Object: val, Expiration: _viewPointExp, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- prom.BusinessErrCount.Incr("mc:AddCacheViewPoint")
- log.Errorv(c, log.KV("AddCacheViewPoint", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
- func (d *Dao) CacheViewPoint(c context.Context, id int64, cid int64) (res *arcMdl.ViewPointRow, err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- key := viewPointCacheKey(id, cid)
- reply, err := conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- prom.BusinessErrCount.Incr("mc:CacheViewPoint")
- log.Errorv(c, log.KV("CacheViewPoint", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- res = &arcMdl.ViewPointRow{}
- err = conn.Scan(reply, res)
- if err != nil {
- prom.BusinessErrCount.Incr("mc:CacheViewPoint")
- log.Errorv(c, log.KV("CacheViewPoint", fmt.Sprintf("%+v", err)), log.KV("key", key))
- return
- }
- return
- }
|