diff --git a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/body_type/dto/response/BodyTypeDto.java b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/body_type/dto/response/BodyTypeDto.java index 3fb8764a..fa050e18 100644 --- a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/body_type/dto/response/BodyTypeDto.java +++ b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/body_type/dto/response/BodyTypeDto.java @@ -5,12 +5,14 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import softeer.be_my_car_master.domain.body_type.BodyType; @Getter @Setter @Builder +@NoArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) public class BodyTypeDto { diff --git a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/body_type/usecase/get_body_types/GetBodyTypesUseCase.java b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/body_type/usecase/get_body_types/GetBodyTypesUseCase.java index de37de33..15edda7e 100644 --- a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/body_type/usecase/get_body_types/GetBodyTypesUseCase.java +++ b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/body_type/usecase/get_body_types/GetBodyTypesUseCase.java @@ -2,6 +2,8 @@ import java.util.List; +import org.springframework.cache.annotation.Cacheable; + import lombok.RequiredArgsConstructor; import softeer.be_my_car_master.application.body_type.dto.response.GetBodyTypesResponse; import softeer.be_my_car_master.domain.body_type.BodyType; @@ -13,6 +15,7 @@ public class GetBodyTypesUseCase { private final GetBodyTypesPort port; + @Cacheable(value = "get_body_types", key = "'modelId=' + #modelId", unless = "#result == null") public GetBodyTypesResponse execute(Long modelId) { List bodyTypes = port.findBodyTypesByModel(modelId); return GetBodyTypesResponse.from(bodyTypes); diff --git a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/car_master/usecase/get_car_masters/GetCarMasterUseCase.java b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/car_master/usecase/get_car_masters/GetCarMasterUseCase.java index 8bb03ba9..42201fb4 100644 --- a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/car_master/usecase/get_car_masters/GetCarMasterUseCase.java +++ b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/car_master/usecase/get_car_masters/GetCarMasterUseCase.java @@ -18,7 +18,6 @@ public class GetCarMasterUseCase { private final GetCarMastersPort port; - // @Cacheable(value = "redis", key = "#latitude + '_' + #longitude", unless = "#result == null") public GetCarMasterResponse execute(Double latitude, Double longitude) { List agencies = port.findAgenciesByLocation(latitude, longitude); diff --git a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/option/dto/response/OptionDto.java b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/option/dto/response/OptionDto.java index 5b8eb5c9..563f4d05 100644 --- a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/option/dto/response/OptionDto.java +++ b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/option/dto/response/OptionDto.java @@ -8,12 +8,14 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import softeer.be_my_car_master.domain.option.Option; @Getter @Setter @Builder +@NoArgsConstructor @AllArgsConstructor(access = AccessLevel.PRIVATE) public class OptionDto { diff --git a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/option/dto/response/SubOptionDto.java b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/option/dto/response/SubOptionDto.java index dde2d83b..c5dee79b 100644 --- a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/option/dto/response/SubOptionDto.java +++ b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/option/dto/response/SubOptionDto.java @@ -4,12 +4,14 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import softeer.be_my_car_master.domain.option.Option; @Getter @Setter @Builder +@NoArgsConstructor @AllArgsConstructor public class SubOptionDto { diff --git a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/option/usecase/get_options/GetOptionsUseCase.java b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/option/usecase/get_options/GetOptionsUseCase.java index 3e5da5ef..5c730d20 100644 --- a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/option/usecase/get_options/GetOptionsUseCase.java +++ b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/option/usecase/get_options/GetOptionsUseCase.java @@ -5,6 +5,8 @@ import java.util.Set; import java.util.stream.Collectors; +import org.springframework.cache.annotation.Cacheable; + import lombok.RequiredArgsConstructor; import softeer.be_my_car_master.application.option.dto.response.GetOptionsResponse; import softeer.be_my_car_master.domain.option.Option; @@ -16,6 +18,14 @@ public class GetOptionsUseCase { private final GetOptionsPort port; + @Cacheable(value = "get_options", + key = + "'trimId=' + #trimId " + + "+ '_engineId=' + #engineId " + + "+ '_wheelDriveId=' + #wheelDriveId " + + "+ '_bodyTypeId=' + #bodyTypeId " + + "+ '_interiorColorId=' + #interiorColorId", + unless = "#result == null") public GetOptionsResponse execute( Long trimId, Long engineId, diff --git a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/trim/usecase/get_trims/GetTrimsUseCase.java b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/trim/usecase/get_trims/GetTrimsUseCase.java index 3deecfea..b149dd19 100644 --- a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/trim/usecase/get_trims/GetTrimsUseCase.java +++ b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/application/trim/usecase/get_trims/GetTrimsUseCase.java @@ -2,6 +2,8 @@ import java.util.List; +import org.springframework.cache.annotation.Cacheable; + import lombok.RequiredArgsConstructor; import softeer.be_my_car_master.application.trim.dto.response.GetTrimsResponse; import softeer.be_my_car_master.domain.trim.Trim; @@ -13,6 +15,7 @@ public class GetTrimsUseCase { private final GetTrimsPort getTrimsPort; + @Cacheable(value = "get_trims", key = "'modelId=' + #modelId", unless = "#result == null") public GetTrimsResponse execute(Long modelId) { List trims = getTrimsPort.findTrimsByModel(modelId); return GetTrimsResponse.from(trims); diff --git a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/global/config/CacheConfig.java b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/global/config/CacheConfig.java index c9b75c8b..7da66682 100644 --- a/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/global/config/CacheConfig.java +++ b/BE-MyCarMaster/src/main/java/softeer/be_my_car_master/global/config/CacheConfig.java @@ -31,10 +31,10 @@ public RedisCacheConfiguration redisCacheConfiguration() { @Bean public RedisCacheManagerBuilderCustomizer redisCacheManagerBuilderCustomizer() { return (builder) -> builder - .withCacheConfiguration("redis", + .withCacheConfiguration("get_options", RedisCacheConfiguration.defaultCacheConfig() .computePrefixWith(cacheName -> "prefix::" + cacheName + "::") - .entryTtl(Duration.ofSeconds(15)) + .entryTtl(Duration.ZERO) .disableCachingNullValues() .serializeKeysWith( RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()) @@ -43,6 +43,35 @@ public RedisCacheManagerBuilderCustomizer redisCacheManagerBuilderCustomizer() { RedisSerializationContext.SerializationPair.fromSerializer( new GenericJackson2JsonRedisSerializer() ) - )); + ) + ) + .withCacheConfiguration("get_body_types", + RedisCacheConfiguration.defaultCacheConfig() + .computePrefixWith(cacheName -> "prefix::" + cacheName + "::") + .entryTtl(Duration.ZERO) + .disableCachingNullValues() + .serializeKeysWith( + RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()) + ) + .serializeValuesWith( + RedisSerializationContext.SerializationPair.fromSerializer( + new GenericJackson2JsonRedisSerializer() + ) + ) + ) + .withCacheConfiguration("get_trims", + RedisCacheConfiguration.defaultCacheConfig() + .computePrefixWith(cacheName -> "prefix::" + cacheName + "::") + .entryTtl(Duration.ZERO) + .disableCachingNullValues() + .serializeKeysWith( + RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()) + ) + .serializeValuesWith( + RedisSerializationContext.SerializationPair.fromSerializer( + new GenericJackson2JsonRedisSerializer() + ) + ) + ); } }