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