12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- // Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT.
- /*
- Package archive is a generated mc cache package.
- It is generated from:
- type _mc interface {
- // mc: -key=staffKey
- CacheStaffData(c context.Context, key int64) ([]*archive.Staff, error)
- // 这里也支持自定义注释 会替换默认的注释
- // mc: -key=staffKey -expire=3 -encode=json|gzip
- AddCacheStaffData(c context.Context, key int64, value []*archive.Staff) error
- // mc: -key=staffKey
- DelCacheStaffData(c context.Context, key int64) error
- }
- */
- package archive
- import (
- "context"
- "fmt"
- "go-common/app/service/main/videoup/model/archive"
- "go-common/library/cache/memcache"
- "go-common/library/log"
- "go-common/library/stat/prom"
- )
- var _ _mc
- // CacheStaffData get data from mc
- func (d *Dao) CacheStaffData(c context.Context, id int64) (res []*archive.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 = []*archive.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
- }
- // AddCacheStaffData 这里也支持自定义注释 会替换默认的注释
- func (d *Dao) AddCacheStaffData(c context.Context, id int64, val []*archive.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
- }
- // DelCacheStaffData delete data from mc
- 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
- }
|