From 0caccc1679c00e0a659dc155a15b9d2ade02d8be Mon Sep 17 00:00:00 2001 From: jsy3831 Date: Sat, 18 Sep 2021 19:57:53 +0900 Subject: [PATCH] =?UTF-8?q?#2=20ehcache=20=EC=9E=84=EC=8B=9C=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + .../com/photobook/PhotobookApplication.java | 2 ++ .../service/impl/UserServiceImpl.java | 2 ++ src/main/resources/ehcache.xml | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+) create mode 100644 src/main/resources/ehcache.xml diff --git a/build.gradle b/build.gradle index fe42113..88b4502 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-aop' implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.boot:spring-boot-starter-cache' // implementation 'org.springframework.boot:spring-boot-starter-data-redis' // implementation 'org.springframework.session:spring-session-data-redis' diff --git a/src/main/java/com/photobook/PhotobookApplication.java b/src/main/java/com/photobook/PhotobookApplication.java index 012ee43..faa3796 100644 --- a/src/main/java/com/photobook/PhotobookApplication.java +++ b/src/main/java/com/photobook/PhotobookApplication.java @@ -2,8 +2,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; @SpringBootApplication +@EnableCaching public class PhotobookApplication { public static void main(String[] args) { diff --git a/src/main/java/com/photobook/service/impl/UserServiceImpl.java b/src/main/java/com/photobook/service/impl/UserServiceImpl.java index a95ea2f..f2d73b9 100644 --- a/src/main/java/com/photobook/service/impl/UserServiceImpl.java +++ b/src/main/java/com/photobook/service/impl/UserServiceImpl.java @@ -4,6 +4,7 @@ import com.photobook.mapper.UserMapper; import com.photobook.dto.UserDto; import com.photobook.service.UserService; +import org.springframework.cache.annotation.Cacheable; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.InternalAuthenticationServiceException; import org.springframework.security.crypto.password.PasswordEncoder; @@ -39,6 +40,7 @@ public UserDto validateLogin(String id, String password) { } @Override + @Cacheable(value="findUserCache", key="#id") public UserDto getUserInfoById(String id) { UserDto userInfo = userMapper.getUserInfoById(id); return userInfo; diff --git a/src/main/resources/ehcache.xml b/src/main/resources/ehcache.xml new file mode 100644 index 0000000..bbae485 --- /dev/null +++ b/src/main/resources/ehcache.xml @@ -0,0 +1,18 @@ + + + + + + + + +