mc_subtitle.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. )
  13. func (d *Dao) subtitleKey(oid int64, subtitleID int64) string {
  14. return fmt.Sprintf(_fmtSubtitle, oid, subtitleID)
  15. }
  16. func (d *Dao) subtitleVideoKey(oid int64, tp int32) string {
  17. return fmt.Sprintf(_fmtVideoSubtitle, oid, tp)
  18. }
  19. func (d *Dao) subtitleDraftKey(oid int64, tp int32, mid int64, lan uint8) string {
  20. return fmt.Sprintf(_fmtSubtitleDraft, oid, tp, mid, lan)
  21. }
  22. // DelVideoSubtitleCache .
  23. func (d *Dao) DelVideoSubtitleCache(c context.Context, oid int64, tp int32) (err error) {
  24. var (
  25. key = d.subtitleVideoKey(oid, tp)
  26. conn = d.subtitleMc.Get(c)
  27. )
  28. defer conn.Close()
  29. if err = conn.Delete(key); err != nil {
  30. if err == memcache.ErrNotFound {
  31. err = nil
  32. } else {
  33. log.Error("memcache.Delete(%s) error(%v)", key, err)
  34. }
  35. }
  36. return
  37. }
  38. // DelSubtitleDraftCache .
  39. func (d *Dao) DelSubtitleDraftCache(c context.Context, oid int64, tp int32, mid int64, lan uint8) (err error) {
  40. var (
  41. key = d.subtitleDraftKey(oid, tp, mid, lan)
  42. conn = d.subtitleMc.Get(c)
  43. )
  44. defer conn.Close()
  45. if err = conn.Delete(key); err != nil {
  46. if err == memcache.ErrNotFound {
  47. err = nil
  48. } else {
  49. log.Error("memcache.Delete(%s) error(%v)", key, err)
  50. }
  51. }
  52. return
  53. }
  54. // DelSubtitleCache .
  55. func (d *Dao) DelSubtitleCache(c context.Context, oid int64, subtitleID int64) (err error) {
  56. var (
  57. key = d.subtitleKey(oid, subtitleID)
  58. conn = d.subtitleMc.Get(c)
  59. )
  60. defer conn.Close()
  61. if err = conn.Delete(key); err != nil {
  62. if err == memcache.ErrNotFound {
  63. err = nil
  64. } else {
  65. log.Error("memcache.Delete(%s) error(%v)", key, err)
  66. }
  67. }
  68. return
  69. }