pull/497/head
gedoor 4 years ago
parent ba7474e966
commit 4743c11676
  1. 14
      app/src/main/java/io/legado/app/help/CacheManager.kt

@ -2,6 +2,7 @@ package io.legado.app.help
import io.legado.app.App import io.legado.app.App
import io.legado.app.data.entities.Cache import io.legado.app.data.entities.Cache
import io.legado.app.utils.ACache
@Suppress("unused") @Suppress("unused")
object CacheManager { object CacheManager {
@ -11,9 +12,13 @@ object CacheManager {
*/ */
@JvmOverloads @JvmOverloads
fun put(key: String, value: Any, saveTime: Int = 0) { fun put(key: String, value: Any, saveTime: Int = 0) {
val deadline = if (saveTime == 0) 0 else System.currentTimeMillis() + saveTime * 1000 if (value is ByteArray) {
val cache = Cache(key, value.toString(), deadline) ACache.get(App.INSTANCE).put(key, value, saveTime)
App.db.cacheDao().insert(cache) } else {
val deadline = if (saveTime == 0) 0 else System.currentTimeMillis() + saveTime * 1000
val cache = Cache(key, value.toString(), deadline)
App.db.cacheDao().insert(cache)
}
} }
fun get(key: String): String? { fun get(key: String): String? {
@ -36,4 +41,7 @@ object CacheManager {
return get(key)?.toFloatOrNull() return get(key)?.toFloatOrNull()
} }
fun getByteArray(key: String) {
ACache.get(App.INSTANCE).getAsBinary(key)
}
} }
Loading…
Cancel
Save