@@ -6,6 +6,8 @@ import io.ktor.client.plugins.cache.storage.CacheStorage
66import io.ktor.client.plugins.cache.storage.CachedResponseData
77import io.ktor.http.Url
88import io.ktor.util.collections.ConcurrentMap
9+ import io.ktor.util.logging.KtorSimpleLogger
10+ import io.ktor.util.logging.trace
911import kotlinx.coroutines.CoroutineDispatcher
1012import kotlinx.coroutines.coroutineScope
1113import kotlinx.coroutines.launch
@@ -46,6 +48,9 @@ internal class FileCacheStorage(
4648) : CacheStorage {
4749 private val mutexes = ConcurrentMap <String , Mutex >()
4850
51+ @Suppress(" ktlint:standard:property-naming" )
52+ private val LOGGER = KtorSimpleLogger (" KtorFileCaching" )
53+
4954 override suspend fun store (
5055 url : Url ,
5156 data : CachedResponseData ,
@@ -115,8 +120,7 @@ internal class FileCacheStorage(
115120 if (Database .getItem(" ${prefix} _$urlHex " ) == null ) return @withLock
116121 Database .removeItem(" ${prefix} _$urlHex " )
117122 } catch (cause: Exception ) {
118- println (" Exception during cache deletion in a file: ${cause.stackTraceToString()} " )
119- // LOGGER.trace { "Exception during cache deletion in a file: ${cause.stackTraceToString()}" }
123+ LOGGER .trace { " Exception during cache deletion in a file: ${cause.stackTraceToString()} " }
120124 }
121125 }
122126 }
@@ -129,8 +133,7 @@ internal class FileCacheStorage(
129133 val serializedData = Cbor .encodeToHexString(caches.map { SerializableCachedResponseData (it) })
130134 Database .setItem(" ${prefix} _$urlHex " , serializedData)
131135 } catch (cause: Exception ) {
132- // LOGGER.trace { "Exception during saving a cache to a file: ${cause.stackTraceToString()}" }
133- println (" Exception during saving a cache to a file: ${cause.stackTraceToString()} " )
136+ LOGGER .trace { " Exception during saving a cache to a file: ${cause.stackTraceToString()} " }
134137 }
135138 }
136139
@@ -139,8 +142,7 @@ internal class FileCacheStorage(
139142 val item = Database .getItem(" ${prefix} _$urlHex " ) ? : return emptySet()
140143 Cbor .decodeFromHexString<Set <SerializableCachedResponseData >>(item).map { it.cachedResponseData }.toSet()
141144 } catch (cause: Exception ) {
142- // LOGGER.trace { "Exception during cache lookup in a file: ${cause.stackTraceToString()}" }
143- println (" Exception during cache lookup in a file: ${cause.stackTraceToString()} " )
145+ LOGGER .trace { " Exception during cache lookup in a file: ${cause.stackTraceToString()} " }
144146 emptySet()
145147 }
146148 }
0 commit comments