-
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: 장소 거리 데이터 cache 적용
- Loading branch information
Showing
14 changed files
with
166 additions
and
118 deletions.
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
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
5 changes: 3 additions & 2 deletions
5
piikii-application/src/main/kotlin/com/piikii/application/domain/course/Distance.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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package com.piikii.application.domain.course | ||
|
||
data class Distance( | ||
val totalDistanceMeter: Int?, | ||
val totalTimeMinute: Int?, | ||
val totalDistanceMeter: Int? = null, | ||
val totalTimeMinute: Int? = null, | ||
) { | ||
companion object { | ||
@JvmField | ||
val EMPTY = Distance(null, null) | ||
} | ||
} |
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
6 changes: 3 additions & 3 deletions
6
piikii-application/src/main/kotlin/com/piikii/application/port/output/web/NavigationPort.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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package com.piikii.application.port.output.web | ||
|
||
import com.piikii.application.domain.course.Coordinate | ||
import com.piikii.application.domain.course.Distance | ||
import com.piikii.application.domain.place.Place | ||
|
||
interface NavigationPort { | ||
fun getDistance( | ||
start: Coordinate, | ||
end: Coordinate, | ||
startPlace: Place, | ||
endPlace: Place, | ||
): Distance | ||
} |
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
90 changes: 62 additions & 28 deletions
90
piikii-output-cache/redis/src/main/kotlin/com/piikii/output/redis/config/RedisConfig.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 |
---|---|---|
@@ -1,48 +1,82 @@ | ||
package com.piikii.output.redis.config | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature | ||
import com.fasterxml.jackson.databind.MapperFeature | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.databind.SerializationFeature | ||
import com.fasterxml.jackson.databind.json.JsonMapper | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties | ||
import org.springframework.cache.CacheManager | ||
import org.springframework.cache.annotation.EnableCaching | ||
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.connection.RedisPassword | ||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration | ||
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory | ||
import org.springframework.data.redis.core.RedisTemplate | ||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories | ||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer | ||
import org.springframework.data.redis.serializer.RedisSerializationContext | ||
import org.springframework.data.redis.serializer.StringRedisSerializer | ||
import java.time.Duration | ||
|
||
// TODO: 필요 시에 등록을 위해 설정 | ||
// @Configuration | ||
@Configuration | ||
@EnableRedisRepositories | ||
@EnableCaching | ||
@EnableConfigurationProperties(RedisProperties::class) | ||
class RedisConfig { | ||
@Value("\${redis.host}") | ||
private val redisHost: String? = null | ||
@Bean | ||
fun lettuceConnectionFactory(redisProperties: RedisProperties): LettuceConnectionFactory { | ||
val redisConfig = | ||
RedisStandaloneConfiguration().apply { | ||
hostName = redisProperties.host | ||
port = redisProperties.port | ||
password = RedisPassword.of(redisProperties.password) | ||
} | ||
|
||
@Value("\${redis.port}") | ||
private val redisPort = 0 | ||
val clientConfig = | ||
LettuceClientConfiguration.builder() | ||
.useSsl() | ||
.build() | ||
|
||
@Bean | ||
fun objectMapper(): ObjectMapper { | ||
return JsonMapper.builder() | ||
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true) | ||
.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false) | ||
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) | ||
.configure(DeserializationFeature.READ_ENUMS_USING_TO_STRING, true) | ||
.findAndAddModules() | ||
.build() | ||
return LettuceConnectionFactory(redisConfig, clientConfig) | ||
} | ||
|
||
@Bean | ||
fun lettuceConnectionFactory(): LettuceConnectionFactory { | ||
return LettuceConnectionFactory(redisHost!!, redisPort) | ||
fun <T> redisTemplate( | ||
redisConnectionFactory: RedisConnectionFactory, | ||
objectMapper: ObjectMapper, | ||
): RedisTemplate<String, T> { | ||
val redisTemplate = RedisTemplate<String, T>() | ||
redisTemplate.connectionFactory = redisConnectionFactory | ||
redisTemplate.keySerializer = StringRedisSerializer() | ||
redisTemplate.valueSerializer = GenericJackson2JsonRedisSerializer(objectMapper) | ||
return redisTemplate | ||
} | ||
|
||
@Bean | ||
fun redistemplate(): RedisTemplate<String, Any> { | ||
val redisTemplate = RedisTemplate<String, Any>() | ||
redisTemplate.connectionFactory = lettuceConnectionFactory() | ||
redisTemplate.keySerializer = StringRedisSerializer() | ||
redisTemplate.valueSerializer = GenericJackson2JsonRedisSerializer(objectMapper()) | ||
return redisTemplate | ||
fun cacheManager(redisConnectionFactory: RedisConnectionFactory): CacheManager { | ||
val redisCacheConfiguration = | ||
RedisCacheConfiguration.defaultCacheConfig() | ||
.entryTtl(Duration.ofDays(7)) | ||
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(StringRedisSerializer())) | ||
.serializeValuesWith( | ||
RedisSerializationContext.SerializationPair.fromSerializer( | ||
GenericJackson2JsonRedisSerializer(), | ||
), | ||
) | ||
|
||
return RedisCacheManager.RedisCacheManagerBuilder | ||
.fromConnectionFactory(redisConnectionFactory) | ||
.cacheDefaults(redisCacheConfiguration) | ||
.build() | ||
} | ||
} | ||
|
||
@ConfigurationProperties(prefix = "redis") | ||
data class RedisProperties( | ||
val host: String, | ||
val port: Int, | ||
val password: String, | ||
) |
7 changes: 0 additions & 7 deletions
7
piikii-output-cache/redis/src/main/resources/cache-config/application-local.yml
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
piikii-output-cache/redis/src/main/resources/cache-config/application-prod.yml
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
piikii-output-cache/redis/src/main/resources/cache-config/application.yml
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,5 @@ | ||
redis: | ||
host: ${REDIS_HOST} | ||
port: 6379 | ||
password: ${REDIS_PASSWORD} | ||
ssl: true |
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
Oops, something went wrong.