From 6c242084ca3b46b4f9824d50308bd7005b34d17e Mon Sep 17 00:00:00 2001 From: len Date: Thu, 3 Aug 2017 21:44:31 +0200 Subject: [PATCH] Fallback chapter cache to internal storage --- .../java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt index cbeb2f43d..0b970356f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/cache/ChapterCache.kt @@ -44,9 +44,13 @@ class ChapterCache(private val context: Context) { /** Google Json class used for parsing JSON files. */ private val gson: Gson by injectLazy() + /** Parent directory of the cache. Ensure not null and not root directory or fallback + * to internal cache directory. **/ + private val basePath = context.externalCacheDir?.takeIf { it.absolutePath.length > 1 } + ?: context.cacheDir + /** Cache class used for cache management. */ - private val diskCache = DiskLruCache.open( - File(context.externalCacheDir, PARAMETER_CACHE_DIRECTORY), + private val diskCache = DiskLruCache.open(File(basePath, PARAMETER_CACHE_DIRECTORY), PARAMETER_APP_VERSION, PARAMETER_VALUE_COUNT, PARAMETER_CACHE_SIZE)