fix:cookie内存缓存bug

pull/1852/head
Xwite 3 years ago
parent 39f368817b
commit 75ef8a17b8
  1. 16
      app/src/main/java/io/legado/app/help/CacheManager.kt
  2. 14
      app/src/main/java/io/legado/app/help/http/CookieStore.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)
}
}

@ -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<String, String> {

Loading…
Cancel
Save