mc.cache.go 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. // Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT.
  2. /*
  3. Package dao is a generated mc cache package.
  4. It is generated from:
  5. type _mc interface {
  6. // get notice data from mc cache.
  7. // mc: -key=noticeKey
  8. CacheNotice(c context.Context, mid int64) (*model.Notice, error)
  9. // set notice data to mc cache.
  10. // mc: -key=noticeKey -expire=d.mcNoticeExpire -encode=pb
  11. AddCacheNotice(c context.Context, mid int64, data *model.Notice) error
  12. // mc: -key=noticeKey
  13. DelCacheNotice(c context.Context, mid int64) error
  14. // get top archive data from mc cache.
  15. // mc: -key=topArcKey
  16. CacheTopArc(c context.Context, mid int64) (*model.AidReason, error)
  17. // set top archive data to mc cache.
  18. // mc: -key=topArcKey -expire=d.mcTopArcExpire -encode=pb
  19. AddCacheTopArc(c context.Context, mid int64, data *model.AidReason) error
  20. // get top archive data from mc cache.
  21. // mc: -key=masterpieceKey
  22. CacheMasterpiece(c context.Context, mid int64) (*model.AidReasons, error)
  23. // set top archive data to mc cache.
  24. // mc: -key=masterpieceKey -expire=d.mcMpExpire -encode=pb
  25. AddCacheMasterpiece(c context.Context, mid int64, data *model.AidReasons) error
  26. // get theme data from mc cache.
  27. // mc: -key=themeKey
  28. CacheTheme(c context.Context, mid int64) (*model.ThemeDetails, error)
  29. // set theme data to mc cache.
  30. // mc: -key=themeKey -expire=d.mcThemeExpire -encode=pb
  31. AddCacheTheme(c context.Context, mid int64, data *model.ThemeDetails) error
  32. // mc: -key=themeKey
  33. DelCacheTheme(c context.Context, mid int64) error
  34. // get top dynamic id cache.
  35. // mc: -key=topDyKey
  36. CacheTopDynamic(c context.Context, key int64) (int64, error)
  37. // set top dynamic id cache.
  38. // mc: -key=topDyKey -expire=d.mcTopDyExpire -encode=raw
  39. AddCacheTopDynamic(c context.Context, key int64, value int64) error
  40. }
  41. */
  42. package dao
  43. import (
  44. "context"
  45. "fmt"
  46. "strconv"
  47. "go-common/app/interface/main/space/model"
  48. "go-common/library/cache/memcache"
  49. "go-common/library/log"
  50. "go-common/library/stat/prom"
  51. )
  52. var _ _mc
  53. // CacheNotice get notice data from mc cache.
  54. func (d *Dao) CacheNotice(c context.Context, id int64) (res *model.Notice, err error) {
  55. conn := d.mc.Get(c)
  56. defer conn.Close()
  57. key := noticeKey(id)
  58. reply, err := conn.Get(key)
  59. if err != nil {
  60. if err == memcache.ErrNotFound {
  61. err = nil
  62. return
  63. }
  64. prom.BusinessErrCount.Incr("mc:CacheNotice")
  65. log.Errorv(c, log.KV("CacheNotice", fmt.Sprintf("%+v", err)), log.KV("key", key))
  66. return
  67. }
  68. res = &model.Notice{}
  69. err = conn.Scan(reply, res)
  70. if err != nil {
  71. prom.BusinessErrCount.Incr("mc:CacheNotice")
  72. log.Errorv(c, log.KV("CacheNotice", fmt.Sprintf("%+v", err)), log.KV("key", key))
  73. return
  74. }
  75. return
  76. }
  77. // AddCacheNotice set notice data to mc cache.
  78. func (d *Dao) AddCacheNotice(c context.Context, id int64, val *model.Notice) (err error) {
  79. if val == nil {
  80. return
  81. }
  82. conn := d.mc.Get(c)
  83. defer conn.Close()
  84. key := noticeKey(id)
  85. item := &memcache.Item{Key: key, Object: val, Expiration: d.mcNoticeExpire, Flags: memcache.FlagProtobuf}
  86. if err = conn.Set(item); err != nil {
  87. prom.BusinessErrCount.Incr("mc:AddCacheNotice")
  88. log.Errorv(c, log.KV("AddCacheNotice", fmt.Sprintf("%+v", err)), log.KV("key", key))
  89. return
  90. }
  91. return
  92. }
  93. // DelCacheNotice delete data from mc
  94. func (d *Dao) DelCacheNotice(c context.Context, id int64) (err error) {
  95. conn := d.mc.Get(c)
  96. defer conn.Close()
  97. key := noticeKey(id)
  98. if err = conn.Delete(key); err != nil {
  99. if err == memcache.ErrNotFound {
  100. err = nil
  101. return
  102. }
  103. prom.BusinessErrCount.Incr("mc:DelCacheNotice")
  104. log.Errorv(c, log.KV("DelCacheNotice", fmt.Sprintf("%+v", err)), log.KV("key", key))
  105. return
  106. }
  107. return
  108. }
  109. // CacheTopArc get top archive data from mc cache.
  110. func (d *Dao) CacheTopArc(c context.Context, id int64) (res *model.AidReason, err error) {
  111. conn := d.mc.Get(c)
  112. defer conn.Close()
  113. key := topArcKey(id)
  114. reply, err := conn.Get(key)
  115. if err != nil {
  116. if err == memcache.ErrNotFound {
  117. err = nil
  118. return
  119. }
  120. prom.BusinessErrCount.Incr("mc:CacheTopArc")
  121. log.Errorv(c, log.KV("CacheTopArc", fmt.Sprintf("%+v", err)), log.KV("key", key))
  122. return
  123. }
  124. res = &model.AidReason{}
  125. err = conn.Scan(reply, res)
  126. if err != nil {
  127. prom.BusinessErrCount.Incr("mc:CacheTopArc")
  128. log.Errorv(c, log.KV("CacheTopArc", fmt.Sprintf("%+v", err)), log.KV("key", key))
  129. return
  130. }
  131. return
  132. }
  133. // AddCacheTopArc set top archive data to mc cache.
  134. func (d *Dao) AddCacheTopArc(c context.Context, id int64, val *model.AidReason) (err error) {
  135. if val == nil {
  136. return
  137. }
  138. conn := d.mc.Get(c)
  139. defer conn.Close()
  140. key := topArcKey(id)
  141. item := &memcache.Item{Key: key, Object: val, Expiration: d.mcTopArcExpire, Flags: memcache.FlagProtobuf}
  142. if err = conn.Set(item); err != nil {
  143. prom.BusinessErrCount.Incr("mc:AddCacheTopArc")
  144. log.Errorv(c, log.KV("AddCacheTopArc", fmt.Sprintf("%+v", err)), log.KV("key", key))
  145. return
  146. }
  147. return
  148. }
  149. // CacheMasterpiece get top archive data from mc cache.
  150. func (d *Dao) CacheMasterpiece(c context.Context, id int64) (res *model.AidReasons, err error) {
  151. conn := d.mc.Get(c)
  152. defer conn.Close()
  153. key := masterpieceKey(id)
  154. reply, err := conn.Get(key)
  155. if err != nil {
  156. if err == memcache.ErrNotFound {
  157. err = nil
  158. return
  159. }
  160. prom.BusinessErrCount.Incr("mc:CacheMasterpiece")
  161. log.Errorv(c, log.KV("CacheMasterpiece", fmt.Sprintf("%+v", err)), log.KV("key", key))
  162. return
  163. }
  164. res = &model.AidReasons{}
  165. err = conn.Scan(reply, res)
  166. if err != nil {
  167. prom.BusinessErrCount.Incr("mc:CacheMasterpiece")
  168. log.Errorv(c, log.KV("CacheMasterpiece", fmt.Sprintf("%+v", err)), log.KV("key", key))
  169. return
  170. }
  171. return
  172. }
  173. // AddCacheMasterpiece set top archive data to mc cache.
  174. func (d *Dao) AddCacheMasterpiece(c context.Context, id int64, val *model.AidReasons) (err error) {
  175. if val == nil {
  176. return
  177. }
  178. conn := d.mc.Get(c)
  179. defer conn.Close()
  180. key := masterpieceKey(id)
  181. item := &memcache.Item{Key: key, Object: val, Expiration: d.mcMpExpire, Flags: memcache.FlagProtobuf}
  182. if err = conn.Set(item); err != nil {
  183. prom.BusinessErrCount.Incr("mc:AddCacheMasterpiece")
  184. log.Errorv(c, log.KV("AddCacheMasterpiece", fmt.Sprintf("%+v", err)), log.KV("key", key))
  185. return
  186. }
  187. return
  188. }
  189. // CacheTheme get theme data from mc cache.
  190. func (d *Dao) CacheTheme(c context.Context, id int64) (res *model.ThemeDetails, err error) {
  191. conn := d.mc.Get(c)
  192. defer conn.Close()
  193. key := themeKey(id)
  194. reply, err := conn.Get(key)
  195. if err != nil {
  196. if err == memcache.ErrNotFound {
  197. err = nil
  198. return
  199. }
  200. prom.BusinessErrCount.Incr("mc:CacheTheme")
  201. log.Errorv(c, log.KV("CacheTheme", fmt.Sprintf("%+v", err)), log.KV("key", key))
  202. return
  203. }
  204. res = &model.ThemeDetails{}
  205. err = conn.Scan(reply, res)
  206. if err != nil {
  207. prom.BusinessErrCount.Incr("mc:CacheTheme")
  208. log.Errorv(c, log.KV("CacheTheme", fmt.Sprintf("%+v", err)), log.KV("key", key))
  209. return
  210. }
  211. return
  212. }
  213. // AddCacheTheme set theme data to mc cache.
  214. func (d *Dao) AddCacheTheme(c context.Context, id int64, val *model.ThemeDetails) (err error) {
  215. if val == nil {
  216. return
  217. }
  218. conn := d.mc.Get(c)
  219. defer conn.Close()
  220. key := themeKey(id)
  221. item := &memcache.Item{Key: key, Object: val, Expiration: d.mcThemeExpire, Flags: memcache.FlagProtobuf}
  222. if err = conn.Set(item); err != nil {
  223. prom.BusinessErrCount.Incr("mc:AddCacheTheme")
  224. log.Errorv(c, log.KV("AddCacheTheme", fmt.Sprintf("%+v", err)), log.KV("key", key))
  225. return
  226. }
  227. return
  228. }
  229. // DelCacheTheme delete data from mc
  230. func (d *Dao) DelCacheTheme(c context.Context, id int64) (err error) {
  231. conn := d.mc.Get(c)
  232. defer conn.Close()
  233. key := themeKey(id)
  234. if err = conn.Delete(key); err != nil {
  235. if err == memcache.ErrNotFound {
  236. err = nil
  237. return
  238. }
  239. prom.BusinessErrCount.Incr("mc:DelCacheTheme")
  240. log.Errorv(c, log.KV("DelCacheTheme", fmt.Sprintf("%+v", err)), log.KV("key", key))
  241. return
  242. }
  243. return
  244. }
  245. // CacheTopDynamic get top dynamic id cache.
  246. func (d *Dao) CacheTopDynamic(c context.Context, id int64) (res int64, err error) {
  247. conn := d.mc.Get(c)
  248. defer conn.Close()
  249. key := topDyKey(id)
  250. reply, err := conn.Get(key)
  251. if err != nil {
  252. if err == memcache.ErrNotFound {
  253. err = nil
  254. return
  255. }
  256. prom.BusinessErrCount.Incr("mc:CacheTopDynamic")
  257. log.Errorv(c, log.KV("CacheTopDynamic", fmt.Sprintf("%+v", err)), log.KV("key", key))
  258. return
  259. }
  260. var v string
  261. err = conn.Scan(reply, &v)
  262. if err != nil {
  263. prom.BusinessErrCount.Incr("mc:CacheTopDynamic")
  264. log.Errorv(c, log.KV("CacheTopDynamic", fmt.Sprintf("%+v", err)), log.KV("key", key))
  265. return
  266. }
  267. r, err := strconv.ParseInt(v, 10, 64)
  268. if err != nil {
  269. prom.BusinessErrCount.Incr("mc:CacheTopDynamic")
  270. log.Errorv(c, log.KV("CacheTopDynamic", fmt.Sprintf("%+v", err)), log.KV("key", key))
  271. return
  272. }
  273. res = int64(r)
  274. return
  275. }
  276. // AddCacheTopDynamic set top dynamic id cache.
  277. func (d *Dao) AddCacheTopDynamic(c context.Context, id int64, val int64) (err error) {
  278. conn := d.mc.Get(c)
  279. defer conn.Close()
  280. key := topDyKey(id)
  281. bs := []byte(strconv.FormatInt(int64(val), 10))
  282. item := &memcache.Item{Key: key, Value: bs, Expiration: d.mcTopDyExpire, Flags: memcache.FlagRAW}
  283. if err = conn.Set(item); err != nil {
  284. prom.BusinessErrCount.Incr("mc:AddCacheTopDynamic")
  285. log.Errorv(c, log.KV("AddCacheTopDynamic", fmt.Sprintf("%+v", err)), log.KV("key", key))
  286. return
  287. }
  288. return
  289. }