diff --git a/module-api/src/main/java/com/kernel360/ModuleApiApplication.java b/module-api/src/main/java/com/kernel360/ModuleApiApplication.java index 01893119..6addf8a4 100644 --- a/module-api/src/main/java/com/kernel360/ModuleApiApplication.java +++ b/module-api/src/main/java/com/kernel360/ModuleApiApplication.java @@ -2,7 +2,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; +@EnableCaching @SpringBootApplication public class ModuleApiApplication { diff --git a/module-api/src/main/java/com/kernel360/global/aop/LogAspect.java b/module-api/src/main/java/com/kernel360/global/aop/LogAspect.java index 922830ff..87e5b06a 100644 --- a/module-api/src/main/java/com/kernel360/global/aop/LogAspect.java +++ b/module-api/src/main/java/com/kernel360/global/aop/LogAspect.java @@ -15,11 +15,11 @@ public class LogAspect { @Around("@annotation(com.kernel360.global.annotation.LogExecutionTime)") public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { - long start = System.currentTimeMillis(); + long start = System.nanoTime(); Object proceed = joinPoint.proceed(); - long executionTime = System.currentTimeMillis() - start; - log.info("##### @LogExecutionTime ##### " + joinPoint.getSignature() + " executed in " + executionTime + "ms"); + long executionTime = System.nanoTime() - start; + log.info("##### @LogExecutionTime ##### " + joinPoint.getSignature() + " executed in " + executionTime + "ns"); return proceed; } @@ -29,13 +29,13 @@ public void controller() {} @Around("controller()") public Object logApiExecTime(ProceedingJoinPoint joinPoint) throws Throwable { - long start = System.currentTimeMillis(); + long start = System.nanoTime(); Object proceed = joinPoint.proceed(); - long executionTime = System.currentTimeMillis() - start; + long executionTime = System.nanoTime() - start; Signature signature = joinPoint.getSignature(); - log.info(String.format("##### @API Execution Time ##### [%dms] → %s.%s", + log.info(String.format("##### @API Execution Time ##### [%dns] → %s.%s", executionTime, signature.getDeclaringTypeName(), signature.getName())); return proceed; diff --git a/module-api/src/main/java/com/kernel360/global/filter/LogFilter.java b/module-api/src/main/java/com/kernel360/global/filter/LogFilter.java index e555c7c7..6df82722 100644 --- a/module-api/src/main/java/com/kernel360/global/filter/LogFilter.java +++ b/module-api/src/main/java/com/kernel360/global/filter/LogFilter.java @@ -15,6 +15,11 @@ @Slf4j @Component public class LogFilter implements Filter { + private static final Trie DENIED_LIST = new PatriciaTrie<>(); + + static { + DENIED_LIST.put("/actuator/prometheus", 0); + } @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { @@ -61,16 +66,9 @@ private static void printLog(FilterChain chain, ContentCachingRequestWrapper req }); String responseBody = new String(response.getContentAsByteArray()); - if(!deninedList().containsKey(uri) && !uri.startsWith("/docs/")) { + if(!DENIED_LIST.containsKey(uri) && !uri.startsWith("/docs/")) { log.info("##### RESPONSE ##### uri: {}, method: {}, header: {}, body: {}", uri, method, responseHeaderValues, responseBody); } response.copyBodyToResponse(); } - - private static Trie deninedList(){ - Trie trie = new PatriciaTrie<>(); - - trie.put("/actuator/prometheus",0); - return trie; - } } diff --git a/module-api/src/main/java/com/kernel360/product/dto/ProductDto.java b/module-api/src/main/java/com/kernel360/product/dto/ProductDto.java index f4930e28..7e56bc83 100644 --- a/module-api/src/main/java/com/kernel360/product/dto/ProductDto.java +++ b/module-api/src/main/java/com/kernel360/product/dto/ProductDto.java @@ -2,12 +2,14 @@ import com.kernel360.product.entity.Product; import com.kernel360.product.enumset.SafetyStatus; + +import java.io.Serializable; import java.time.LocalDateTime; /** * DTO for {@link com.kernel360.product.entity.Product} */ -public record ProductDto( +public record ProductDto ( Long productNo, String productName, String barcode, @@ -21,7 +23,7 @@ public record ProductDto( String createdBy, LocalDateTime modifiedAt, String modifiedBy -) { +) implements Serializable{ public static ProductDto of( Long productNo, diff --git a/module-api/src/main/java/com/kernel360/product/service/ProductService.java b/module-api/src/main/java/com/kernel360/product/service/ProductService.java index e7404b02..c8abccac 100644 --- a/module-api/src/main/java/com/kernel360/product/service/ProductService.java +++ b/module-api/src/main/java/com/kernel360/product/service/ProductService.java @@ -12,6 +12,7 @@ import com.kernel360.product.enumset.SafetyStatus; import com.kernel360.product.repository.ProductRepository; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.Cacheable; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; @@ -27,6 +28,7 @@ public class ProductService { private final ProductRepository productRepository; private final LikeRepository likeRepository; + @Cacheable(value = "productsCache") @Transactional(readOnly = true) public List getProducts() { diff --git a/module-domain/src/main/java/com/kernel360/product/entity/Product.java b/module-domain/src/main/java/com/kernel360/product/entity/Product.java index 4e6f2b09..0ea5d5f3 100644 --- a/module-domain/src/main/java/com/kernel360/product/entity/Product.java +++ b/module-domain/src/main/java/com/kernel360/product/entity/Product.java @@ -13,11 +13,14 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.Cache; +import org.hibernate.annotations.CacheConcurrencyStrategy; @Getter @Entity @Table(name = "product") +@Cache(usage = CacheConcurrencyStrategy.READ_WRITE) @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Product extends BaseEntity {