fix:cookie内存缓存bug

This commit is contained in:
Xwite 2022-05-07 13:10:05 +08:00
parent 39f368817b
commit 75ef8a17b8
2 changed files with 19 additions and 11 deletions

View File

@ -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)
}
}

View File

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