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 @@ + + + + + + + + +