mc_subtitle.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/library/cache/memcache"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _fmtSubtitle = "s_subtitle_%d_%d"
  10. _fmtVideoSubtitle = "s_video_%d_%d"
  11. _fmtSubtitleDraft = "s_draft_%v_%v_%v_%v"
  12. _fmtSubtitleSubject = "s_subtitle_allow_%d"
  13. )
  14. func (d *Dao) subtitleKey(oid int64, subtitleID int64) string {
  15. return fmt.Sprintf(_fmtSubtitle, oid, subtitleID)
  16. }
  17. func (d *Dao) subtitleVideoKey(oid int64, tp int32) string {
  18. return fmt.Sprintf(_fmtVideoSubtitle, oid, tp)
  19. }
  20. func (d *Dao) subtitleDraftKey(oid int64, tp int32, mid int64, lan uint8) string {
  21. return fmt.Sprintf(_fmtSubtitleDraft, oid, tp, mid, lan)
  22. }
  23. func (d *Dao) subtitleSubjectKey(aid int64) string {
  24. return fmt.Sprintf(_fmtSubtitleSubject, aid)
  25. }
  26. // DelVideoSubtitleCache .
  27. func (d *Dao) DelVideoSubtitleCache(c context.Context, oid int64, tp int32) (err error) {
  28. var (
  29. key = d.subtitleVideoKey(oid, tp)
  30. conn = d.subtitleMC.Get(c)
  31. )
  32. defer conn.Close()
  33. if err = conn.Delete(key); err != nil {
  34. if err == memcache.ErrNotFound {
  35. err = nil
  36. } else {
  37. log.Error("memcache.Delete(%s) error(%v)", key, err)
  38. }
  39. }
  40. return
  41. }
  42. // DelSubtitleDraftCache .
  43. func (d *Dao) DelSubtitleDraftCache(c context.Context, oid int64, tp int32, mid int64, lan uint8) (err error) {
  44. var (
  45. key = d.subtitleDraftKey(oid, tp, mid, lan)
  46. conn = d.subtitleMC.Get(c)
  47. )
  48. defer conn.Close()
  49. if err = conn.Delete(key); err != nil {
  50. if err == memcache.ErrNotFound {
  51. err = nil
  52. } else {
  53. log.Error("memcache.Delete(%s) error(%v)", key, err)
  54. }
  55. }
  56. return
  57. }
  58. // DelSubtitleCache .
  59. func (d *Dao) DelSubtitleCache(c context.Context, oid int64, subtitleID int64) (err error) {
  60. var (
  61. key = d.subtitleKey(oid, subtitleID)
  62. conn = d.subtitleMC.Get(c)
  63. )
  64. defer conn.Close()
  65. if err = conn.Delete(key); err != nil {
  66. if err == memcache.ErrNotFound {
  67. err = nil
  68. } else {
  69. log.Error("memcache.Delete(%s) error(%v)", key, err)
  70. }
  71. }
  72. return
  73. }
  74. // DelSubtitleSubjectCache .
  75. func (d *Dao) DelSubtitleSubjectCache(c context.Context, aid int64) (err error) {
  76. var (
  77. key = d.subtitleSubjectKey(aid)
  78. conn = d.subtitleMC.Get(c)
  79. )
  80. defer conn.Close()
  81. if err = conn.Delete(key); err != nil {
  82. if err == memcache.ErrNotFound {
  83. err = nil
  84. } else {
  85. log.Error("memcache.Delete(%s) error(%v)", key, err)
  86. }
  87. }
  88. return
  89. }