perf:验证码 浏览器页面内容缓存到内存

This commit is contained in:
Xwite
2022-05-05 17:33:34 +08:00
parent d6203bb5e4
commit a045a246da
3 changed files with 11 additions and 6 deletions
@@ -35,6 +35,11 @@ object CacheManager {
} }
} }
fun putMemory(key: String, value: Any) {
val cache = Cache(key, value.toString(), 0)
memoryLruCache.put(key, cache)
}
fun get(key: String): String? { fun get(key: String): String? {
return getFromMemory(key) ?: appDb.cacheDao.get(key, System.currentTimeMillis()) return getFromMemory(key) ?: appDb.cacheDao.get(key, System.currentTimeMillis())
} }
@@ -19,7 +19,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
/** /**
* 图片验证码对话框 * 图片验证码对话框
* 结果保存在数据库 * 结果保存在内存
* val key = "${sourceOrigin ?: ""}_verificationResult" * val key = "${sourceOrigin ?: ""}_verificationResult"
* CacheManager.get(key) * CacheManager.get(key)
*/ */
@@ -62,8 +62,8 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification
} }
tvOk.setOnClickListener { tvOk.setOnClickListener {
val verificationCode = binding.verificationCode.text.toString() val verificationCode = binding.verificationCode.text.toString()
verificationCode?.let { verificationCode.let {
CacheManager.put(key, it) CacheManager.putMemory(key, it)
dismiss() dismiss()
} }
} }
@@ -75,8 +75,8 @@ class VerificationCodeDialog() : BaseDialogFragment(R.layout.dialog_verification
override fun onDestroy() { override fun onDestroy() {
val sourceOrigin = arguments?.getString("sourceOrigin") val sourceOrigin = arguments?.getString("sourceOrigin")
val key = "${sourceOrigin ?: ""}_verificationResult" val key = "${sourceOrigin}_verificationResult"
CacheManager.get(key) ?: CacheManager.put(key, "") CacheManager.get(key) ?: CacheManager.putMemory(key, "")
super.onDestroy() super.onDestroy()
activity?.finish() activity?.finish()
} }
@@ -87,7 +87,7 @@ class WebViewModel(application: Application) : BaseViewModel(application) {
if (sourceVerificationEnable) { if (sourceVerificationEnable) {
val key = "${sourceOrigin}_verificationResult" val key = "${sourceOrigin}_verificationResult"
html = AnalyzeUrl(baseUrl, headerMapF = headerMap).getStrResponse(useWebView = false).body html = AnalyzeUrl(baseUrl, headerMapF = headerMap).getStrResponse(useWebView = false).body
CacheManager.put(key, html ?: "") CacheManager.putMemory(key, html ?: "")
} }
} }