From abfe9af9a6a1f01ea2528eb078b742a9a3e2b7d2 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Mon, 13 Jan 2025 20:42:11 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=BA=90=EC=8B=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/few/api/repo/config/LocalCacheConfig.kt | 14 ++++++++++++++ .../com/few/api/repo/dao/article/ArticleDao.kt | 2 +- .../few/api/repo/dao/article/ArticleMainCardDao.kt | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/api-repo/src/main/kotlin/com/few/api/repo/config/LocalCacheConfig.kt b/api-repo/src/main/kotlin/com/few/api/repo/config/LocalCacheConfig.kt index 9ee3a86ee..227b171bc 100644 --- a/api-repo/src/main/kotlin/com/few/api/repo/config/LocalCacheConfig.kt +++ b/api-repo/src/main/kotlin/com/few/api/repo/config/LocalCacheConfig.kt @@ -25,6 +25,7 @@ class LocalCacheConfig { const val SELECT_ARTICLE_RECORD_CACHE = "selectArticleRecordCache" const val SELECT_WORKBOOK_RECORD_CACHE = "selectWorkBookRecordCache" const val SELECT_WRITER_CACHE = "selectWritersCache" + const val SELECT_ARTICLE_MAIN_CARD_CACHE = "selectArticleMainCardCache" } @Bean(LOCAL_CM) @@ -40,6 +41,15 @@ class LocalCacheConfig { ) val cacheManager = EhcacheCachingProvider().cacheManager + val cache100Configuration = CacheConfigurationBuilder.newCacheConfigurationBuilder( + Any::class.java, + Any::class.java, + ResourcePoolsBuilder.newResourcePoolsBuilder() + .heap(100, EntryUnit.ENTRIES) + ) + .withService(cacheEventListenerConfigurationConfig) + .build() + val cache10Configuration = CacheConfigurationBuilder.newCacheConfigurationBuilder( Any::class.java, Any::class.java, @@ -58,6 +68,9 @@ class LocalCacheConfig { .withService(cacheEventListenerConfigurationConfig) .build() + val selectArticleMainCardCacheConfig: javax.cache.configuration.Configuration = + Eh107Configuration.fromEhcacheCacheConfiguration(cache100Configuration) + val selectArticleRecordCacheConfig: javax.cache.configuration.Configuration = Eh107Configuration.fromEhcacheCacheConfiguration(cache10Configuration) val selectWorkBookRecordCacheConfig: javax.cache.configuration.Configuration = @@ -70,6 +83,7 @@ class LocalCacheConfig { cacheManager.createCache(SELECT_ARTICLE_RECORD_CACHE, selectArticleRecordCacheConfig) cacheManager.createCache(SELECT_WORKBOOK_RECORD_CACHE, selectWorkBookRecordCacheConfig) cacheManager.createCache(SELECT_WRITER_CACHE, selectWriterCacheConfig) + cacheManager.createCache(SELECT_ARTICLE_MAIN_CARD_CACHE, selectArticleMainCardCacheConfig) }.onFailure { log.error(it) { "Failed to create cache" } } diff --git a/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleDao.kt b/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleDao.kt index db528860a..ea8de7144 100644 --- a/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleDao.kt +++ b/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleDao.kt @@ -18,7 +18,6 @@ class ArticleDao( private val dslContext: DSLContext, ) { - @Cacheable(key = "#query.articleId", cacheManager = LOCAL_CM, cacheNames = [SELECT_ARTICLE_RECORD_CACHE]) fun selectArticleRecord(query: SelectArticleRecordQuery): SelectArticleRecord? { return selectArticleRecordQuery(query) .fetchOneInto(SelectArticleRecord::class.java) @@ -128,6 +127,7 @@ class ArticleDao( selectArticleContentsQuery(articleIds) .fetchInto(SelectArticleContentsRecord::class.java) + @Cacheable(key = "#articleId", cacheManager = LOCAL_CM, cacheNames = [SELECT_ARTICLE_RECORD_CACHE]) fun selectArticleContent(articleId: Long): SelectArticleContentsRecord? = dslContext.select( ArticleIfo.ARTICLE_IFO.ARTICLE_MST_ID.`as`(SelectArticleContentsRecord::articleId.name), ArticleIfo.ARTICLE_IFO.CONTENT.`as`(SelectArticleContentsRecord::content.name) diff --git a/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleMainCardDao.kt b/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleMainCardDao.kt index ccceabacf..5fa984a7a 100644 --- a/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleMainCardDao.kt +++ b/api-repo/src/main/kotlin/com/few/api/repo/dao/article/ArticleMainCardDao.kt @@ -1,5 +1,7 @@ package com.few.api.repo.dao.article +import com.few.api.repo.config.LocalCacheConfig.Companion.LOCAL_CM +import com.few.api.repo.config.LocalCacheConfig.Companion.SELECT_ARTICLE_MAIN_CARD_CACHE import com.few.api.repo.dao.article.command.ArticleMainCardExcludeWorkbookCommand import com.few.api.repo.dao.article.command.UpdateArticleMainCardWorkbookCommand import com.few.api.repo.dao.article.record.ArticleMainCardRecord @@ -8,6 +10,7 @@ import com.few.api.repo.dao.article.support.ArticleMainCardMapper import jooq.jooq_dsl.tables.ArticleMainCard.ARTICLE_MAIN_CARD import org.jooq.* import org.jooq.impl.DSL.* +import org.springframework.cache.annotation.Cacheable import org.springframework.stereotype.Repository @Repository @@ -23,6 +26,7 @@ class ArticleMainCardDao( .toSet() } + @Cacheable(key = "#articleId", cacheManager = LOCAL_CM, cacheNames = [SELECT_ARTICLE_MAIN_CARD_CACHE]) fun selectArticleMainCardRecord(articleId: Long): ArticleMainCardRecord? = dslContext.select( ARTICLE_MAIN_CARD.ID.`as`(ArticleMainCardRecord::articleId.name),