|
|
|
|
@ -2,12 +2,20 @@ package org.koitharu.kotatsu.utils
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import androidx.annotation.WorkerThread
|
|
|
|
|
import okhttp3.Cache
|
|
|
|
|
import okhttp3.CacheControl
|
|
|
|
|
import org.koitharu.kotatsu.utils.ext.computeSize
|
|
|
|
|
import org.koitharu.kotatsu.utils.ext.sub
|
|
|
|
|
import org.koitharu.kotatsu.utils.ext.sumByLong
|
|
|
|
|
|
|
|
|
|
object CacheUtils {
|
|
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
|
val CONTROL_DISABLED = CacheControl.Builder()
|
|
|
|
|
.noCache()
|
|
|
|
|
.noStore()
|
|
|
|
|
.build()
|
|
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
|
fun getCacheDirs(context: Context) = (context.externalCacheDirs + context.cacheDir)
|
|
|
|
|
.filterNotNull()
|
|
|
|
|
@ -24,4 +32,10 @@ object CacheUtils {
|
|
|
|
|
fun clearCache(context: Context, name: String) = getCacheDirs(context)
|
|
|
|
|
.map { it.sub(name) }
|
|
|
|
|
.forEach { it.deleteRecursively() }
|
|
|
|
|
|
|
|
|
|
@JvmStatic
|
|
|
|
|
fun createHttpCache(context: Context) = Cache(
|
|
|
|
|
directory = (context.externalCacheDir ?: context.cacheDir).sub("http"),
|
|
|
|
|
maxSize = FileSizeUtils.mbToBytes(60)
|
|
|
|
|
)
|
|
|
|
|
}
|