Skip to content

Commit

Permalink
Merge pull request #73 from nowgnas/LF1-968-cache
Browse files Browse the repository at this point in the history
Lf1 968 cache
  • Loading branch information
nowgnas authored Jan 9, 2024
2 parents 3572ffb + f77df21 commit 37c65b2
Show file tree
Hide file tree
Showing 42 changed files with 396 additions and 121 deletions.
31 changes: 0 additions & 31 deletions .github/release-drafter-config.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name-template: "User v$RESOLVED_VERSION"
tag-template: "v$RESOLVED_VERSION"
categories:
- title: "🆕 새로운 기능이 추가되었어요!"
label: "✨ Feature"
- title: "🐞 자잘한 버그를 수정했습니다."
label: "🐞 Bugfix"
- title: "🫶🏻 앱 사용성 개선에 힘썼습니다."
label: "🫶🏻 Improvement"
- title: "🛠️ 더 나은 코드를 위해 노력하고 있습니다."
labels:
- "🔨 Refactor"
- "⚙️ Setting"
- title: "ETC"
labels:
- "*"
change-template: "* $TITLE (#$NUMBER) by @$AUTHOR"
change-title-escapes: '\<*_&#@`'
exclude-labels:
- "Main"
version-resolver:
major:
labels:
- "Major"
minor:
labels:
- "Minor"
patch:
labels:
- "Patch"
default: patch
template: |
$CHANGES
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter-config.yml
config-name: release.yml
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }}

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ out/
docker.sh
*.DS_Store
data.sql
ProductKafkaTest.java
ProductKafkaTest.java
Test.java
13 changes: 12 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,20 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'de.flapdoodle.embed:de.flapdoodle.embed.mongo'
testImplementation 'org.mockito:mockito-core:4.8.0'
implementation 'io.github.lotteon-maven:blooming-blooms-utils:202401010607'
implementation 'io.github.lotteon-maven:blooming-blooms-utils:202401040316'
testImplementation 'com.github.tomakehurst:wiremock:2.27.2'

// redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation("it.ozimov:embedded-redis:0.7.2")
implementation 'org.redisson:redisson-spring-boot-starter:3.17.0'

// testcontainers
testImplementation "org.junit.jupiter:junit-jupiter:5.8.1"
testImplementation "org.testcontainers:testcontainers:1.17.6"
testImplementation "org.testcontainers:junit-jupiter:1.17.6"


}

dependencyManagement {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/kr/bb/product/ProductServiceApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
Expand All @@ -10,6 +11,7 @@
@EnableEurekaClient
@EnableFeignClients
@EnableAspectJAutoProxy
@EnableCaching
public class ProductServiceApplication {

public static void main(String[] args) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/kr/bb/product/common/aop/LoggingHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class LoggingHandler {
private static final Logger logger = LoggerFactory.getLogger(LoggingHandler.class);

@Value("${spring.config.active.on-profile}")
@Value("${spring.config.active.on-profile:local}")
private String activeProfile;

@Around("within(kr.bb.product.domain..*)")
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/kr/bb/product/common/entity/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package kr.bb.product.common.entity;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.EntityListeners;
Expand All @@ -16,9 +20,13 @@
public class BaseEntity {
@CreatedDate
@Column(name = "created_at")
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime createdAt;

@LastModifiedDate
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@Column(name = "updated_at")
private LocalDateTime updatedAt;

Expand Down
60 changes: 60 additions & 0 deletions src/main/java/kr/bb/product/config/CacheConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package kr.bb.product.config;

import java.time.Duration;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.CacheManager;
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;

@Configuration
@RequiredArgsConstructor
public class CacheConfiguration {
private static final String PRODUCT = "product";

@Bean
public CacheManager redisCacheManager(RedisConnectionFactory redisConnectionFactory) {
RedisCacheConfiguration redisCacheConfiguration =
RedisCacheConfiguration.defaultCacheConfig()
.serializeKeysWith(
RedisSerializationContext.SerializationPair.fromSerializer(
new StringRedisSerializer()))
.serializeValuesWith(
RedisSerializationContext.SerializationPair.fromSerializer(
new GenericJackson2JsonRedisSerializer()));

return RedisCacheManager.RedisCacheManagerBuilder.fromConnectionFactory(redisConnectionFactory)
.cacheDefaults(redisCacheConfiguration)
.withCacheConfiguration(PRODUCT, redisCacheConfigurationPromotion())
.build();
}

@Bean
public RedisCacheConfiguration redisCacheConfiguration() {
return RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofMinutes(1))
.disableCachingNullValues()
.serializeKeysWith(
RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
.serializeValuesWith(
RedisSerializationContext.SerializationPair.fromSerializer(
new GenericJackson2JsonRedisSerializer()));
}

@Bean
public RedisCacheConfiguration redisCacheConfigurationPromotion() {
return RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofMinutes(30))
.disableCachingNullValues()
.serializeKeysWith(
RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
.serializeValuesWith(
RedisSerializationContext.SerializationPair.fromSerializer(
new GenericJackson2JsonRedisSerializer()));
}
}
43 changes: 43 additions & 0 deletions src/main/java/kr/bb/product/config/RedisConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package kr.bb.product.config;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
@RequiredArgsConstructor
public class RedisConfiguration {
@Value("${spring.redis.host}")
private String host;

@Value("${spring.redis.port}")
private int port;

@Value("${spring.redis.password}")
private String password;

@Bean
public RedisConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(host);
redisStandaloneConfiguration.setPort(port);
redisStandaloneConfiguration.setPassword(password);
return new LettuceConnectionFactory(redisStandaloneConfiguration);
}

@Bean
public RedisTemplate<String, String> redisTemplate(
RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
redisTemplate.setConnectionFactory(redisConnectionFactory);
return redisTemplate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
Expand All @@ -34,6 +35,7 @@
@Repository
@RequiredArgsConstructor
public class ProductQueryRepository implements ProductQueryOutPort {
private static final String PRODUCT = "product";
private final ProductMongoRepository productMongoRepository;
private final MongoTemplate mongoTemplate;

Expand Down Expand Up @@ -142,6 +144,7 @@ public Product findSubscriptionProductByStoreId(Long storeId) {
}

@Override
@Cacheable(cacheNames = PRODUCT, key = "#selectOption")
public List<Product> findMainPageProducts(SelectOption selectOption) {
Query query =
new Query(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;
import java.util.Map;
import kr.bb.product.domain.product.mapper.ProductCommand;
import kr.bb.product.domain.product.mapper.ProductCommand.MainPageProductItems;
import kr.bb.product.domain.product.mapper.ProductCommand.ProductList;
import kr.bb.product.domain.product.mapper.ProductCommand.SortOption;
import kr.bb.product.domain.product.mapper.ProductCommand.StoreProductList;
Expand Down Expand Up @@ -80,7 +81,7 @@ ProductCommand.SubscriptionProductForCustomer getSubscriptionProductDetail(

List<LikedProductInfoResponse> getProductInformationForLikes(List<String> productIds);

Map<Long, Double> getStoreAverageRating();
Map<Long, Double> getStoreAverageRating();

List<StockChangeDto> getFlowerAmountGroupByStoreId(ProcessOrderDto processOrderDto);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package kr.bb.product.domain.product.entity;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -92,12 +96,16 @@ public class Product {
@NotBlank
@Builder.Default
@CreatedDate
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@Field(name = "created_at")
private LocalDateTime createdAt = LocalDateTime.now();

@NotBlank
@Builder.Default
@LastModifiedDate
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@Field(name = "updated_at")
private LocalDateTime updatedAt = LocalDateTime.now();

Expand Down
Loading

0 comments on commit 37c65b2

Please sign in to comment.