2021-12-11 18:30:22 +08:00

80 lines
2.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.java2nb.novel.controller;
import com.java2nb.novel.core.cache.CacheKey;
import com.java2nb.novel.core.cache.CacheService;
import com.java2nb.novel.core.enums.ResponseStatus;
import com.java2nb.novel.service.BookService;
import com.java2nb.novel.service.FriendLinkService;
import com.java2nb.novel.service.NewsService;
import io.github.xxyopen.model.resp.RestResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author 11797
*/
@RequestMapping("cache")
@RestController
@Slf4j
@RequiredArgsConstructor
public class CacheController {
@Value("${cache.manager.password}")
private String cacheManagerPass;
private final CacheService cacheService;
private final BookService bookService;
private final NewsService newsService;
private final FriendLinkService friendLinkService;
/**
* 刷新缓存
* @param type 缓存类型1首页书籍推荐2首页新闻3首页友情链接
* */
@GetMapping("refresh/{pass}/{type}")
public RestResult<Void> refreshCache(@PathVariable("type") Byte type, @PathVariable("pass") String pass){
if(!cacheManagerPass.equals(pass)){
return RestResult.fail(ResponseStatus.PASSWORD_ERROR);
}
switch (type){
case 1:{
//刷新首页推荐书籍缓存
cacheService.del(CacheKey.INDEX_BOOK_SETTINGS_KEY);
bookService.listBookSettingVO();
break;
}
case 2:{
//刷新首页新闻缓存
cacheService.del(CacheKey.INDEX_NEWS_KEY);
newsService.listIndexNews();
break;
}
case 3:{
//刷新首页友情链接
cacheService.del(CacheKey.INDEX_LINK_KEY);
friendLinkService.listIndexLink();
break;
}
default:{
break;
}
}
return RestResult.ok();
}
}