diff --git a/modules/comment/dao/comment.go b/modules/comment/dao/comment.go index edd8657..61cf834 100644 --- a/modules/comment/dao/comment.go +++ b/modules/comment/dao/comment.go @@ -3,7 +3,6 @@ package dao import ( "context" "errors" - "fmt" "time" "github.com/NTHU-LSALAB/NTHU-Distributed-System/modules/comment/pb" @@ -42,8 +41,9 @@ var ( ErrCommentNotFound = errors.New("comment not found") ) +// key format: "listComment:{videoID}:{limit}:{offset}" func listCommentKey(videoID string, limit, offset int) string { - return fmt.Sprintf("listComment:%s:%d:%d", videoID, limit, offset) + // Redis TODO } func NewFakeComment(videoID string) *Comment { diff --git a/modules/comment/dao/comment_redis.go b/modules/comment/dao/comment_redis.go index 413bb92..670a50f 100644 --- a/modules/comment/dao/comment_redis.go +++ b/modules/comment/dao/comment_redis.go @@ -22,46 +22,35 @@ const ( commentDAORedisCacheDuration = 3 * time.Minute ) +// create redisCommentDAO by cache and baseDAO func NewRedisCommentDAO(client *rediskit.RedisClient, baseDAO CommentDAO) *redisCommentDAO { - return &redisCommentDAO{ - cache: cache.New(&cache.Options{ - Redis: client, - LocalCache: cache.NewTinyLFU(commentDAOLocalCacheSize, commentDAOLocalCacheDuration), - }), - baseDAO: baseDAO, - } + // Redis TODO } +// List all the comments related to the videoID +// Notice that all the comments will be stored as a single value in the cache +// The key is generated by listCommentKey function in comment.go +// The implementation should handle both cache miss and cache hit scenarios func (dao *redisCommentDAO) ListByVideoID(ctx context.Context, videoID string, limit, offset int) ([]*Comment, error) { - var comment []*Comment - - if err := dao.cache.Once(&cache.Item{ - Key: listCommentKey(videoID, limit, offset), - Value: &comment, - TTL: commentDAORedisCacheDuration, - Do: func(*cache.Item) (interface{}, error) { - return dao.baseDAO.ListByVideoID(ctx, videoID, limit, offset) - }, - }); err != nil { - return nil, err - } - return comment, nil + // Redis TODO } -// The following operations are not cachable, just pass down to baseDAO - +// The operation are not cacheable, just pass down to baseDAO func (dao *redisCommentDAO) Create(ctx context.Context, comment *Comment) (uuid.UUID, error) { - return dao.baseDAO.Create(ctx, comment) + // Redis TODO } +// The following operations are not cacheable, just pass down to baseDAO func (dao *redisCommentDAO) Update(ctx context.Context, comment *Comment) error { - return dao.baseDAO.Update(ctx, comment) + // Redis TODO } +// The following operations are not cacheable, just pass down to baseDAO func (dao *redisCommentDAO) Delete(ctx context.Context, id uuid.UUID) error { - return dao.baseDAO.Delete(ctx, id) + // Redis TODO } +// The following operations are not cacheable, just pass down to baseDAO func (dao *redisCommentDAO) DeleteByVideoID(ctx context.Context, videoID string) error { - return dao.baseDAO.DeleteByVideoID(ctx, videoID) + // Redis TODO }