-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: 로컬 캐시(EHCache) 디펜던시 추가 In api-repo 모듈 * feat: EHCache 설정 적용 및 신규 캐시 키(selectArticleRecordCache) 추가 * refactor: ehcache 설정 xml -> javaconfig 변경 * feat: SelectArticleRecord에 Serializable 추가 * feat: LocalCacheConfig의 상수 활용하는 방법으로 수정 * refactor: EHCache에서 event.newValue, oldValue 로깅하지 않도록 변경 * refactor: localCacheProvider 선언 * refactor: EhcacheCachingProvider로 수정 --------- Co-authored-by: belljun3395 <[email protected]>
- Loading branch information
1 parent
85136c9
commit 656db6d
Showing
6 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
api-repo/src/main/kotlin/com/few/api/repo/common/LocalCacheEventLogger.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.few.api.repo.common | ||
|
||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.ehcache.event.CacheEvent | ||
import org.ehcache.event.CacheEventListener | ||
|
||
class LocalCacheEventLogger : CacheEventListener<Any, Any> { | ||
private val log = KotlinLogging.logger {} | ||
|
||
override fun onEvent(event: CacheEvent<out Any, out Any>) { | ||
log.debug { "Local Cache event: ${event.type} for item with key: ${event.key}. " } | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
api-repo/src/main/kotlin/com/few/api/repo/config/LocalCacheConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.few.api.repo.config | ||
|
||
import com.few.api.repo.common.LocalCacheEventLogger | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.ehcache.config.builders.CacheConfigurationBuilder | ||
import org.ehcache.config.builders.ResourcePoolsBuilder | ||
import org.ehcache.config.units.EntryUnit | ||
import org.ehcache.event.EventType | ||
import org.ehcache.impl.config.event.DefaultCacheEventListenerConfiguration | ||
import org.ehcache.jsr107.Eh107Configuration | ||
import org.ehcache.jsr107.EhcacheCachingProvider | ||
import org.springframework.cache.CacheManager | ||
import org.springframework.cache.annotation.EnableCaching | ||
import org.springframework.cache.jcache.JCacheCacheManager | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
@EnableCaching | ||
class LocalCacheConfig { | ||
private val log = KotlinLogging.logger {} | ||
|
||
companion object { | ||
const val LOCAL_CM = "localCacheManager" | ||
const val SELECT_ARTICLE_RECORD_CACHE = "selectArticleRecordCache" | ||
} | ||
|
||
@Bean(LOCAL_CM) | ||
fun localCacheManager(): CacheManager { | ||
val cacheEventListenerConfigurationConfig = DefaultCacheEventListenerConfiguration( | ||
setOf( | ||
EventType.CREATED, | ||
EventType.EXPIRED, | ||
EventType.REMOVED, | ||
EventType.UPDATED | ||
), | ||
LocalCacheEventLogger::class.java | ||
) | ||
val cacheManager = EhcacheCachingProvider().cacheManager | ||
|
||
val cacheConfigurationBuilder = CacheConfigurationBuilder.newCacheConfigurationBuilder( | ||
Any::class.java, | ||
Any::class.java, | ||
ResourcePoolsBuilder.newResourcePoolsBuilder() | ||
.heap(50, EntryUnit.ENTRIES) | ||
) | ||
.withService(cacheEventListenerConfigurationConfig) | ||
.build() | ||
|
||
val selectArticleRecordCacheConfig: javax.cache.configuration.Configuration<Any, Any> = | ||
Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfigurationBuilder) | ||
runCatching { | ||
cacheManager.createCache(SELECT_ARTICLE_RECORD_CACHE, selectArticleRecordCacheConfig) | ||
}.onFailure { | ||
log.error(it) { "Failed to create cache" } | ||
} | ||
|
||
return JCacheCacheManager(cacheManager) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters