mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
Merge pull request #1502 from Xwite/master
cacheFile:首次下没有返回下载内容;ACache:saveTime=0视为永久保存
This commit is contained in:
commit
aee6ff7cf8
@ -28,6 +28,10 @@ object CacheManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun putString2File(key: String, value: String, saveTime: Int = 0) {
|
||||||
|
ACache.get(appCtx).put(key, value, saveTime)
|
||||||
|
}
|
||||||
|
|
||||||
fun get(key: String): String? {
|
fun get(key: String): String? {
|
||||||
return appDb.cacheDao.get(key, System.currentTimeMillis())
|
return appDb.cacheDao.get(key, System.currentTimeMillis())
|
||||||
}
|
}
|
||||||
@ -52,6 +56,10 @@ object CacheManager {
|
|||||||
return ACache.get(appCtx).getAsBinary(key)
|
return ACache.get(appCtx).getAsBinary(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getString(key: String): String? {
|
||||||
|
return ACache.get(appCtx).getAsString(key)
|
||||||
|
}
|
||||||
|
|
||||||
fun getQueryTTF(key: String): QueryTTF? {
|
fun getQueryTTF(key: String): QueryTTF? {
|
||||||
val cache = queryTTFMap[key] ?: return null
|
val cache = queryTTFMap[key] ?: return null
|
||||||
if (cache.first == 0L || cache.first > System.currentTimeMillis()) {
|
if (cache.first == 0L || cache.first > System.currentTimeMillis()) {
|
||||||
|
@ -138,15 +138,14 @@ interface JsExtensions {
|
|||||||
* @param saveTime 缓存时间,单位:秒
|
* @param saveTime 缓存时间,单位:秒
|
||||||
* @return 返回缓存后的文件内容
|
* @return 返回缓存后的文件内容
|
||||||
*/
|
*/
|
||||||
fun cacheFile(url: String, saveTime: Int = 0): String? {
|
fun cacheFile(urlStr: String, saveTime: Int = 0): String? {
|
||||||
val key = md5Encode16(url)
|
val key = md5Encode16(urlStr)
|
||||||
val cache = ACache.get(appCtx).getAsString(key)
|
val cache = CacheManager.getString(key)
|
||||||
if(cache.isNullOrBlank()) {
|
if(cache.isNullOrBlank()) {
|
||||||
log("首次下载${url}...")
|
log("首次下载 ${urlStr}")
|
||||||
val value = ajax(url) ?: ""
|
val value = ajax(urlStr) ?: return null
|
||||||
if (saveTime == 0) {
|
CacheManager.putString2File(key, value, saveTime)
|
||||||
ACache.get(appCtx).put(key, value)
|
return value
|
||||||
} else ACache.get(appCtx).put(key, value, saveTime)
|
|
||||||
}
|
}
|
||||||
return cache
|
return cache
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
|
|||||||
* @param saveTime 保存的时间,单位:秒
|
* @param saveTime 保存的时间,单位:秒
|
||||||
*/
|
*/
|
||||||
fun put(key: String, value: String, saveTime: Int) {
|
fun put(key: String, value: String, saveTime: Int) {
|
||||||
put(key, Utils.newStringWithDateInfo(saveTime, value))
|
if (saveTime == 0) put(key, value) else put(key, Utils.newStringWithDateInfo(saveTime, value))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -245,7 +245,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
|
|||||||
* @param saveTime 保存的时间,单位:秒
|
* @param saveTime 保存的时间,单位:秒
|
||||||
*/
|
*/
|
||||||
fun put(key: String, value: ByteArray, saveTime: Int) {
|
fun put(key: String, value: ByteArray, saveTime: Int) {
|
||||||
put(key, Utils.newByteArrayWithDateInfo(saveTime, value))
|
if (saveTime == 0) put(key, value) else put(key, Utils.newByteArrayWithDateInfo(saveTime, value))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user