From 75ef8a17b8d810ac12d134ab91c9be68273e41c3 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sat, 7 May 2022 13:10:05 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9Acookie=E5=86=85=E5=AD=98=E7=BC=93?= =?UTF-8?q?=E5=AD=98bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/CacheManager.kt | 16 ++++++++++------ .../java/io/legado/app/help/http/CookieStore.kt | 14 +++++++++----- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/CacheManager.kt b/app/src/main/java/io/legado/app/help/CacheManager.kt index b4bab56f5..9cdac800d 100644 --- a/app/src/main/java/io/legado/app/help/CacheManager.kt +++ b/app/src/main/java/io/legado/app/help/CacheManager.kt @@ -35,6 +35,15 @@ object CacheManager { memoryLruCache.put(key, value) } + //从内存中获取数据 使用lruCache + fun getFromMemory(key: String): String? { + return memoryLruCache.get(key) + } + + fun deleteMemory(key: String) { + memoryLruCache.remove(key) + } + fun get(key: String): String? { getFromMemory(key)?.let { return it @@ -47,11 +56,6 @@ object CacheManager { return null } - //从内存中获取数据 使用lruCache - fun getFromMemory(key: String): String? { - return memoryLruCache.get(key) - } - fun getInt(key: String): Int? { return get(key)?.toIntOrNull() } @@ -92,7 +96,7 @@ object CacheManager { fun delete(key: String) { appDb.cacheDao.delete(key) - memoryLruCache.remove(key) + deleteMemory(key) ACache.get(appCtx).remove(key) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/http/CookieStore.kt b/app/src/main/java/io/legado/app/help/http/CookieStore.kt index b0d892b36..ace5ac5ca 100644 --- a/app/src/main/java/io/legado/app/help/http/CookieStore.kt +++ b/app/src/main/java/io/legado/app/help/http/CookieStore.kt @@ -15,8 +15,9 @@ object CookieStore : CookieManager { *保存cookie到数据库,会自动识别url的二级域名 */ override fun setCookie(url: String, cookie: String?) { - CacheManager.putMemory(url, cookie ?: "") - val cookieBean = Cookie(NetworkUtils.getSubDomain(url), cookie ?: "") + val domain = NetworkUtils.getSubDomain(url) + CacheManager.putMemory("${domain}_cookie", cookie ?: "") + val cookieBean = Cookie(domain, cookie ?: "") appDb.cookieDao.insert(cookieBean) } @@ -39,8 +40,9 @@ object CookieStore : CookieManager { *获取url所属的二级域名的cookie */ override fun getCookie(url: String): String { - CacheManager.getFromMemory(url)?.let { return it } - val cookieBean = appDb.cookieDao.get(NetworkUtils.getSubDomain(url)) + val domain = NetworkUtils.getSubDomain(url) + CacheManager.getFromMemory("${domain}_cookie")?.let { return it } + val cookieBean = appDb.cookieDao.get(domain) val cookie = cookieBean?.cookie ?: "" CacheManager.putMemory(url, cookie ?: "") return cookie @@ -53,7 +55,9 @@ object CookieStore : CookieManager { } override fun removeCookie(url: String) { - appDb.cookieDao.delete(NetworkUtils.getSubDomain(url)) + val domain = NetworkUtils.getSubDomain(url) + CacheManager.deleteMemory("${domain}_cookie") + appDb.cookieDao.delete(domain) } override fun cookieToMap(cookie: String): MutableMap {