diff --git a/app/src/main/java/com/hippo/ehviewer/EhApplication.kt b/app/src/main/java/com/hippo/ehviewer/EhApplication.kt index 5643f8720..6085b2057 100644 --- a/app/src/main/java/com/hippo/ehviewer/EhApplication.kt +++ b/app/src/main/java/com/hippo/ehviewer/EhApplication.kt @@ -50,7 +50,9 @@ import eu.kanade.tachiyomi.util.lang.launchIO import io.ktor.client.HttpClient import io.ktor.client.engine.okhttp.OkHttp import kotlinx.coroutines.DelicateCoroutinesApi +import okhttp3.Cache import okhttp3.OkHttpClient +import okio.FileSystem import okio.Path.Companion.toOkioPath import java.net.Proxy import java.security.KeyStore @@ -193,7 +195,7 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor override fun newImageLoader(): ImageLoader { return ImageLoader.Builder(this).apply { - okHttpClient(okHttpClient) + okHttpClient(nonCacheOkHttpClient) components { add(MergeInterceptor) } diskCache(imageCache) crossfade(300) @@ -213,8 +215,7 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor @JvmStatic val ehProxySelector by lazy { EhProxySelector() } - @JvmStatic - val okHttpClient by lazy { + val nonCacheOkHttpClient by lazy { val builder = OkHttpClient.Builder() .cookieJar(EhCookieStore) .dns(EhDns) @@ -233,10 +234,21 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor builder.build() } + // Never use this okhttp client to download large blobs!!! + val okHttpClient by lazy { + nonCacheOkHttpClient.newBuilder().cache( + Cache( + application.cacheDir.toOkioPath() / "http_cache", + 20L * 1024L * 1024L, + FileSystem.SYSTEM + ) + ).build() + } + val ktorClient by lazy { HttpClient(OkHttp) { engine { - preconfigured = okHttpClient + preconfigured = nonCacheOkHttpClient } } } diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhTagDatabase.kt b/app/src/main/java/com/hippo/ehviewer/client/EhTagDatabase.kt index bef45fa33..e931a5add 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhTagDatabase.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/EhTagDatabase.kt @@ -18,7 +18,7 @@ package com.hippo.ehviewer.client import android.content.Context import com.hippo.ehviewer.AppConfig import com.hippo.ehviewer.EhApplication -import com.hippo.ehviewer.EhApplication.Companion.okHttpClient +import com.hippo.ehviewer.EhApplication.Companion.nonCacheOkHttpClient import com.hippo.ehviewer.R import com.hippo.util.HashCodeUtils import com.hippo.yorozuya.FileUtils @@ -250,7 +250,7 @@ object EhTagDatabase { FileUtils.delete(dataFile) } } - val client = okHttpClient + val client = nonCacheOkHttpClient // Save new sha1 val tempSha1File = File(dir, "$sha1Name.tmp") diff --git a/app/src/main/java/com/hippo/ehviewer/legacy/CleanupObsoleteCache.kt b/app/src/main/java/com/hippo/ehviewer/legacy/CleanupObsoleteCache.kt index 186ed9ff3..dce224265 100644 --- a/app/src/main/java/com/hippo/ehviewer/legacy/CleanupObsoleteCache.kt +++ b/app/src/main/java/com/hippo/ehviewer/legacy/CleanupObsoleteCache.kt @@ -8,7 +8,6 @@ import java.io.File private val OBSOLETE_CACHE_DIRS = arrayOf( "image", "thumb", - "http_cache", "image_cache", "gallery_image", "spider_info"