This commit is contained in:
kunfei
2022-09-20 14:01:50 +08:00
parent a5b77af9f9
commit a1cac7a837
2 changed files with 7 additions and 7 deletions

View File

@@ -17,12 +17,12 @@ private val mutexMap by lazy { hashMapOf<String, Mutex>() }
private val exploreKindsMap by lazy { ConcurrentHashMap<String, List<ExploreKind>>() }
private val aCache by lazy { ACache.get("explore") }
private fun BookSource.exploreKindsKey(): String {
private fun BookSource.getExploreKindsKey(): String {
return MD5Utils.md5Encode(bookSourceUrl + exploreUrl)
}
suspend fun BookSource.exploreKinds(): List<ExploreKind> {
val exploreKindsKey = exploreKindsKey()
val exploreKindsKey = getExploreKindsKey()
exploreKindsMap[exploreKindsKey]?.let { return it }
val exploreUrl = exploreUrl
if (exploreUrl.isNullOrBlank()) {
@@ -30,7 +30,7 @@ suspend fun BookSource.exploreKinds(): List<ExploreKind> {
}
val mutex = mutexMap[bookSourceUrl] ?: Mutex().apply { mutexMap[bookSourceUrl] = this }
mutex.withLock {
exploreKindsMap[exploreKindsKey()]?.let { return it }
exploreKindsMap[exploreKindsKey]?.let { return it }
val kinds = arrayListOf<ExploreKind>()
var ruleStr: String = exploreUrl
withContext(Dispatchers.IO) {
@@ -72,6 +72,6 @@ suspend fun BookSource.exploreKinds(): List<ExploreKind> {
suspend fun BookSource.clearExploreKindsCache() {
withContext(Dispatchers.IO) {
aCache.remove(bookSourceUrl)
exploreKindsMap.remove(exploreKindsKey())
exploreKindsMap.remove(getExploreKindsKey())
}
}

View File

@@ -8,13 +8,13 @@ import kotlinx.coroutines.withContext
private val aCache by lazy { ACache.get("rssSortUrl") }
private fun RssSource.sortUrlsKey(): String {
private fun RssSource.getSortUrlsKey(): String {
return MD5Utils.md5Encode(sourceUrl + sortUrl)
}
suspend fun RssSource.sortUrls(): List<Pair<String, String>> =
arrayListOf<Pair<String, String>>().apply {
val sortUrlsKey = sortUrlsKey()
val sortUrlsKey = getSortUrlsKey()
withContext(Dispatchers.IO) {
kotlin.runCatching {
var a = sortUrl
@@ -46,6 +46,6 @@ suspend fun RssSource.sortUrls(): List<Pair<String, String>> =
suspend fun RssSource.removeSortCache() {
withContext(Dispatchers.IO) {
aCache.remove(sortUrlsKey())
aCache.remove(getSortUrlsKey())
}
}