Skip to content

Commit

Permalink
feat: loadUserByUsername 유저 캐싱 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
gmlrude committed Aug 23, 2024
1 parent 8a609f3 commit d36aba9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@

public interface UserRepository extends JpaRepository<User,Long> {
boolean existsByUsername(String username);

Optional<User> findUserByUsername(String username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.techeer.checkIt.domain.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
Expand All @@ -19,6 +20,7 @@ public class CustomUserDetailService implements UserDetailsService {
private final UserRepository userRepository;

@Override
@Cacheable("users")
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
log.info("loadUserByUsername called for username: {}", username);
User principal = userRepository.findUserByUsername(username)
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/techeer/checkIt/global/config/CacheConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.techeer.checkIt.global.config;

import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableCaching
public class CacheConfig {
@Bean
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager("users");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.techeer.checkIt.global.config;

import com.techeer.checkIt.domain.book.repository.BookJpaRepository;
import com.techeer.checkIt.domain.book.repository.BookSearchRepository;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
Expand Down

0 comments on commit d36aba9

Please sign in to comment.