You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.8 KiB
78 lines
1.8 KiB
package dao |
|
|
|
import ( |
|
"context" |
|
"fmt" |
|
|
|
"go-common/library/cache/memcache" |
|
"go-common/library/log" |
|
) |
|
|
|
const ( |
|
_fmtSubtitle = "s_subtitle_%d_%d" |
|
_fmtVideoSubtitle = "s_video_%d_%d" |
|
_fmtSubtitleDraft = "s_draft_%v_%v_%v_%v" |
|
) |
|
|
|
func (d *Dao) subtitleKey(oid int64, subtitleID int64) string { |
|
return fmt.Sprintf(_fmtSubtitle, oid, subtitleID) |
|
} |
|
|
|
func (d *Dao) subtitleVideoKey(oid int64, tp int32) string { |
|
return fmt.Sprintf(_fmtVideoSubtitle, oid, tp) |
|
} |
|
|
|
func (d *Dao) subtitleDraftKey(oid int64, tp int32, mid int64, lan uint8) string { |
|
return fmt.Sprintf(_fmtSubtitleDraft, oid, tp, mid, lan) |
|
} |
|
|
|
// DelVideoSubtitleCache . |
|
func (d *Dao) DelVideoSubtitleCache(c context.Context, oid int64, tp int32) (err error) { |
|
var ( |
|
key = d.subtitleVideoKey(oid, tp) |
|
conn = d.subtitleMc.Get(c) |
|
) |
|
defer conn.Close() |
|
if err = conn.Delete(key); err != nil { |
|
if err == memcache.ErrNotFound { |
|
err = nil |
|
} else { |
|
log.Error("memcache.Delete(%s) error(%v)", key, err) |
|
} |
|
} |
|
return |
|
} |
|
|
|
// DelSubtitleDraftCache . |
|
func (d *Dao) DelSubtitleDraftCache(c context.Context, oid int64, tp int32, mid int64, lan uint8) (err error) { |
|
var ( |
|
key = d.subtitleDraftKey(oid, tp, mid, lan) |
|
conn = d.subtitleMc.Get(c) |
|
) |
|
defer conn.Close() |
|
if err = conn.Delete(key); err != nil { |
|
if err == memcache.ErrNotFound { |
|
err = nil |
|
} else { |
|
log.Error("memcache.Delete(%s) error(%v)", key, err) |
|
} |
|
} |
|
return |
|
} |
|
|
|
// DelSubtitleCache . |
|
func (d *Dao) DelSubtitleCache(c context.Context, oid int64, subtitleID int64) (err error) { |
|
var ( |
|
key = d.subtitleKey(oid, subtitleID) |
|
conn = d.subtitleMc.Get(c) |
|
) |
|
defer conn.Close() |
|
if err = conn.Delete(key); err != nil { |
|
if err == memcache.ErrNotFound { |
|
err = nil |
|
} else { |
|
log.Error("memcache.Delete(%s) error(%v)", key, err) |
|
} |
|
} |
|
return |
|
}
|
|
|