-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/#31 마이페이지 추가 #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 5 commits
d71bfb7
cfefe28
f5b69d0
243fac4
b0b4a43
d2cc693
f35a7f1
e8f39ec
ae0d98a
f9414ab
b15de47
c039cc4
e30d91b
3fcd035
b88478b
41f9655
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.whereyouad.WhereYouAd.domains.user.application.dto.response; | ||
|
|
||
| public record MyPageResponse( | ||
| Long userId, | ||
| String email, | ||
| String name, | ||
| String profileImageUrl, | ||
| String phoneNumber, | ||
| boolean isEmailVerified | ||
| ) { | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package com.whereyouad.WhereYouAd.domains.user.domain.service; | ||
|
|
||
| import com.whereyouad.WhereYouAd.domains.user.application.dto.response.MyPageResponse; | ||
| import com.whereyouad.WhereYouAd.domains.user.exception.handler.UserHandler; | ||
| import com.whereyouad.WhereYouAd.domains.user.exception.code.UserErrorCode; | ||
| import com.whereyouad.WhereYouAd.domains.user.domain.constant.UserStatus; | ||
|
|
@@ -10,6 +11,7 @@ | |
| import com.whereyouad.WhereYouAd.domains.user.persistence.repository.UserRepository; | ||
| import com.whereyouad.WhereYouAd.global.utils.RedisUtil; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.cache.annotation.Cacheable; | ||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
@@ -85,4 +87,19 @@ public void passwordReset(String email, String password) { | |
|
|
||
| redisUtil.deleteData("VERIFIED:" + email); | ||
| } | ||
|
|
||
| /** | ||
| * 마이페이지 메서드 Redis 캐싱 적용 | ||
| * 동작 방식: Redis에서 'user:profile::{userId}' 키를 먼저 조회, | ||
| * 데이터가 존재하면 메서드를 실행하지 않고(DB 조회 X) 캐시된 데이터를 즉시 반환 | ||
| * 데이터가 없으면 DB에서 조회 후 반환, 결과값을 자동으로 Redis에 저장 | ||
| */ | ||
| @Cacheable(value = "user:profile", key = "#userId", unless = "#result == null") | ||
| @Transactional(readOnly = true) | ||
| public MyPageResponse getMyPage(Long userId) { | ||
| User user = userRepository.findById(userId) | ||
| .orElseThrow(() -> new UserHandler(UserErrorCode.USER_NOT_FOUND)); | ||
|
|
||
| return UserConverter.toMyPageResponse(user); | ||
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.whereyouad.WhereYouAd.global.config; | ||
|
|
||
| import org.springframework.cache.annotation.EnableCaching; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.data.redis.cache.RedisCacheConfiguration; | ||
| import org.springframework.data.redis.cache.RedisCacheManager; | ||
| import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
| import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; | ||
| import org.springframework.data.redis.serializer.RedisSerializationContext; | ||
| import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
|
||
| import java.time.Duration; | ||
|
|
||
| @Configuration | ||
| @EnableCaching | ||
| public class RedisConfig { | ||
|
|
||
| @Bean | ||
| public RedisCacheManager cacheManager(RedisConnectionFactory connectionFactory) { | ||
| // Redis 캐시 설정 정의 | ||
| RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig() | ||
| // Key 직렬화: String ("user:profile::1" 처럼 보기 좋게 저장) | ||
| .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())) | ||
| // Value 직렬화: JSON (자바 객체 -> JSON 변환 저장) | ||
| .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())) | ||
| // TTL 설정: 데이터 유효 시간 (30분) | ||
| .entryTtl(Duration.ofMinutes(30)) | ||
| // null 데이터는 캐싱하지 않음 | ||
| .disableCachingNullValues(); | ||
|
|
||
| return RedisCacheManager.builder(connectionFactory) | ||
| .cacheDefaults(config) | ||
| .build(); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.