Skip to content

Commit

Permalink
feat: 캐시 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Jan 13, 2025
1 parent 1fae88b commit abfe9af
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -58,6 +68,9 @@ class LocalCacheConfig {
.withService(cacheEventListenerConfigurationConfig)
.build()

val selectArticleMainCardCacheConfig: javax.cache.configuration.Configuration<Any, Any> =
Eh107Configuration.fromEhcacheCacheConfiguration(cache100Configuration)

val selectArticleRecordCacheConfig: javax.cache.configuration.Configuration<Any, Any> =
Eh107Configuration.fromEhcacheCacheConfiguration(cache10Configuration)
val selectWorkBookRecordCacheConfig: javax.cache.configuration.Configuration<Any, Any> =
Expand All @@ -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" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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),
Expand Down

0 comments on commit abfe9af

Please sign in to comment.