content: package io.github.xxyopen.novel.book.manager.cache;
  
  import io.github.xxyopen.novel.book.dao.entity.BookChapter;
  import io.github.xxyopen.novel.book.dao.mapper.BookChapterMapper;
  import io.github.xxyopen.novel.book.dto.resp.BookChapterRespDto;
  import io.github.xxyopen.novel.common.constant.CacheConsts;
  import lombok.RequiredArgsConstructor;
  import org.springframework.cache.annotation.Cacheable;
  import org.springframework.stereotype.Component;
  
  /**
   * 小说章节 缓存管理类
   *
   * @author xiongxiaoyang
   * @date 2022/5/12
   */
  @Component
  @RequiredArgsConstructor
  public class BookChapterCacheManager {
  
      private final BookChapterMapper bookChapterMapper;
  
      /**
       * 查询小说章节信息，并放入缓存中
       */
      @Cacheable(cacheManager = CacheConsts.CAFFEINE_CACHE_MANAGER,
          value = CacheConsts.BOOK_CHAPTER_CACHE_NAME)
      public BookChapterRespDto getChapter(Long chapterId) {
          BookChapter bookChapter = bookChapterMapper.selectById(chapterId);
          return BookChapterRespDto.builder()
              .id(chapterId)
              .bookId(bookChapter.getBookId())
              .chapterNum(bookChapter.getChapterNum())
              .chapterName(bookChapter.getChapterName())
              .chapterWordCount(bookChapter.getWordCount())
              .chapterUpdateTime(bookChapter.getUpdateTime())
              .build();
      }
  
  
  }
  