From 099d9a81bb3a78e0569a89cc2b02069f38d3bb48 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Thu, 6 Jan 2022 22:07:29 +0800 Subject: [PATCH] =?UTF-8?q?cacheFile:=E7=BC=93=E5=AD=98=E8=87=B3=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=80=8C=E4=B8=8D=E6=98=AF=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/JsExtensions.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index 903a2024d..adde0e962 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -126,27 +126,29 @@ interface JsExtensions { } /** - * 缓存网络文件 + * 缓存以文本方式保存的文件 如.js .txt等 */ fun cacheFile(urlStr: String): String? { return cacheFile(urlStr, 0) } - /** - * 缓存网络文件 + /** + * 缓存以文本方式保存的文件 如.js .txt等 * @param url 网络文件的链接 * @param saveTime 缓存时间,单位:秒 * @return 返回缓存后的文件内容 */ fun cacheFile(url: String, saveTime: Int = 0): String? { val key = md5Encode16(url) - val cache = CacheManager.get(key) - if (cache.isNullOrBlank()) { - log("首次下载${url}...") - val value = ajax(url) ?: "" - CacheManager.put(key, value as Any, saveTime) - } - return cache + val cache = ACache.get(appCtx).getAsString(key) + if(cache.isNullOrBlank()) { + log("首次下载${url}...") + val value = ajax(url) ?: "" + if (saveTime == 0) { + ACache.get(appCtx).put(key, value) + } else ACache.get(appCtx).put(key, value, saveTime) + } + return cache } /**