feat(本地缓存): 加入本地缓存功能

1.项目第一次启动 查数据库 加入redis 加入本地缓存
2.第二次启动 查询redis 加入本地缓存
This commit is contained in:
ovo 2024-12-23 17:25:04 +08:00
parent 89f8550dff
commit a6a12a3b04
5 changed files with 16 additions and 12 deletions

View File

@ -1,5 +1,6 @@
package com.guwan.backend.controller; package com.guwan.backend.controller;
import com.guwan.backend.common.BusinessException;
import com.guwan.backend.common.Result; import com.guwan.backend.common.Result;
import com.guwan.backend.pojo.entity.BookCategory; import com.guwan.backend.pojo.entity.BookCategory;
import com.guwan.backend.service.BookCategoryService; import com.guwan.backend.service.BookCategoryService;
@ -46,8 +47,7 @@ public class BookCategoryController {
*/ */
@GetMapping("{id}") @GetMapping("{id}")
public Result<BookCategory> queryById(@PathVariable("id") Integer id) { public Result<BookCategory> queryById(@PathVariable("id") Integer id) {
// return Result.success(this.bookCategoryService.queryById(id)); return Result.success(bookCategoryService.getById(id));
return Result.success();
} }
/** /**
@ -58,7 +58,11 @@ public class BookCategoryController {
*/ */
@PostMapping @PostMapping
public Result<BookCategory> add(BookCategory bookCategory) { public Result<BookCategory> add(BookCategory bookCategory) {
// return Result.success(this.bookCategoryService.insert(bookCategory));
if (bookCategoryService.lambdaQuery()
.eq(BookCategory::getCategoryName, bookCategory.getCategoryName()).one() != null){
throw new BusinessException("该图书种类已经存在");
}
if (bookCategoryService.save(bookCategory)) { if (bookCategoryService.save(bookCategory)) {
return Result.success(); return Result.success();
@ -88,7 +92,7 @@ public class BookCategoryController {
*/ */
@DeleteMapping @DeleteMapping
public Result<Boolean> deleteById(Integer id) { public Result<Boolean> deleteById(Integer id) {
// return Result.success(this.bookCategoryService.deleteById(id)); bookCategoryService.removeById(id);
return Result.success(); return Result.success();
} }

View File

@ -2,6 +2,7 @@ package com.guwan.backend.controller.monitor;
import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.stats.CacheStats; import com.github.benmanes.caffeine.cache.stats.CacheStats;
import com.guwan.backend.annotation.OperationLog;
import com.guwan.backend.common.BusinessException; import com.guwan.backend.common.BusinessException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.CacheManager; import org.springframework.cache.CacheManager;
@ -25,6 +26,7 @@ public class CacheMonitor {
} }
@GetMapping("/stats") @GetMapping("/stats")
@OperationLog(description = "根据名称获取本地缓存使用情况")
public Map<String, Object> getStats(String cacheName) { public Map<String, Object> getStats(String cacheName) {
CaffeineCacheManager caffeineCacheManager = (CaffeineCacheManager) cacheManager; CaffeineCacheManager caffeineCacheManager = (CaffeineCacheManager) cacheManager;
Cache<Object, Object> nativeCache = null; Cache<Object, Object> nativeCache = null;

View File

@ -200,6 +200,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
@Override @Override
@OperationLog(description = "修改密码")
public void resetPassword(ChangePasswordDTO changePasswordDTO) { public void resetPassword(ChangePasswordDTO changePasswordDTO) {
if(changePasswordDTO.getChangeWay().equals(UserEnums.ACCOUNT.getValue())){ if(changePasswordDTO.getChangeWay().equals(UserEnums.ACCOUNT.getValue())){
@ -238,6 +239,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
} }
@Override @Override
@OperationLog(description = "刷新token")
public String refreshToken(String token) { public String refreshToken(String token) {
return null; return null;
} }

View File

@ -10,8 +10,6 @@ $!callback.setSavePath($tool.append($tableInfo.savePath, "/controller"))
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller; #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -57,8 +55,7 @@ public Result<Page<$!{tableInfo.name}>> queryByPage($!{tableInfo.name} $!{tool.f
*/ */
@GetMapping("{id}") @GetMapping("{id}")
public Result<$!{tableInfo.name}> queryById(@PathVariable("id") $!pk.shortType id) { public Result<$!{tableInfo.name}> queryById(@PathVariable("id") $!pk.shortType id) {
// return Result.success(this.$!{tool.firstLowerCase($tableInfo.name)}Service.queryById(id)); return Result.success(this.$!{tool.firstLowerCase($tableInfo.name)}Service.getById(id));
return Result.success();
} }
/** /**
@ -69,7 +66,7 @@ public Result<$!{tableInfo.name}> queryById(@PathVariable("id") $!pk.shortType i
*/ */
@PostMapping @PostMapping
public Result<$!{tableInfo.name}> add($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) { public Result<$!{tableInfo.name}> add($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
// return Result.success(this.$!{tool.firstLowerCase($tableInfo.name)}Service.insert($!{tool.firstLowerCase($tableInfo.name)})); this.$!{tool.firstLowerCase($tableInfo.name)}Service.save($!{tool.firstLowerCase($tableInfo.name)});
return Result.success(); return Result.success();
} }
@ -93,8 +90,7 @@ public Result<$!{tableInfo.name}> edit($!{tableInfo.name} $!{tool.firstLowerCase
*/ */
@DeleteMapping @DeleteMapping
public Result<Boolean> deleteById($!pk.shortType id) { public Result<Boolean> deleteById($!pk.shortType id) {
// return Result.success(this.$!{tool.firstLowerCase($tableInfo.name)}Service.deleteById(id)); return Result.success(this.$!{tool.firstLowerCase($tableInfo.name)}Service.removeById(id));
return Result.success();
} }
} }

File diff suppressed because one or more lines are too long