Skip to content

Commit

Permalink
Initialize application cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jsixface committed Jan 20, 2025
1 parent f678a71 commit f2d8182
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fun Application.module() {
migrateDatabases()
configureRouting()
configureHTTP()
initialize()
}


Expand Down
18 changes: 18 additions & 0 deletions server/src/main/kotlin/io/github/jsixface/codexvert/Initializer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.github.jsixface.codexvert

import io.github.jsixface.codexvert.api.VideoApi
import io.ktor.server.application.Application
import io.ktor.server.application.log
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.koin.ktor.ext.inject

fun Application.initialize() {
val videoApi by inject<VideoApi>()
log.info("initialize application...")

CoroutineScope(Dispatchers.IO).launch {
videoApi.updateCache()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class VideoApi(private val parser: IParser, private val repo: IVideoFilesRepo) {
private val logger = logger()
private var cache = emptyList<VideoFile>()

private suspend fun updateCache() {
suspend fun updateCache() {
logger.info("${this::class.simpleName} updateCache()")
cache = repo.getAll().map { it.toVideoFile() }
}
Expand Down

0 comments on commit f2d8182

Please sign in to comment.