Bring back httpcache, but for non-Image only

This commit is contained in:
tarsin committed 2023-03-07 11:49:02 +08:00
1 parent 10def6e48a
commit 6a184462c6
3 files changed
+18 -7

No files matched your search

@@ -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
}
}
}
@@ -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")
@@ -8,7 +8,6 @@ import java.io.File
private val OBSOLETE_CACHE_DIRS = arrayOf(
"image",
"thumb",
"http_cache",
"image_cache",
"gallery_image",
"spider_info"