@@ -95,10 +95,8 @@ class APIRepository(val api: MainAPI) {
9595 }
9696
9797 fun getEffectiveHomepageCacheTtl (maxHomepageCacheTimeMs : Long? ): Long {
98- val userCacheTtl = DataStoreHelper .cacheTimeSeconds
99- if (userCacheTtl <= 0L ) return 0L
100- val providerMaxSeconds = maxHomepageCacheTimeMs?.let { it / 1000L } ? : return userCacheTtl
101- return if (providerMaxSeconds <= 0L ) 0L else minOf(userCacheTtl, providerMaxSeconds)
98+ val userTtl = DataStoreHelper .cacheTimeSeconds.coerceAtLeast(0L )
99+ return maxHomepageCacheTimeMs?.let { minOf(userTtl, it / 1000L ).coerceAtLeast(0L ) } ? : userTtl
102100 }
103101
104102 fun hasHomePageCache (
@@ -110,13 +108,10 @@ class APIRepository(val api: MainAPI) {
110108 val cacheTtl = getEffectiveHomepageCacheTtl(maxHomepageCacheTimeMs)
111109 if (cacheTtl <= 0L ) return false
112110 val lookingForHash = Pair (apiName, Pair (page, nameIndex))
113- val inRam = homeCache.withLock {
111+ return homeCache.withLock {
114112 homeCache.any { it.hash == lookingForHash && unixTime - it.unixTime < cacheTtl }
115- }
116- if (inRam) return true
117- val diskKey = " ${apiName} _${page} _${nameIndex} "
118- val onDisk = CloudStreamApp .getKey<SavedHomePageResponse >(HOME_CACHE_FOLDER , diskKey)
119- return onDisk != null && unixTime - onDisk.unixTime < cacheTtl
113+ } || CloudStreamApp .getKey<SavedHomePageResponse >(HOME_CACHE_FOLDER , " ${apiName} _${page} _${nameIndex} " )
114+ ?.let { unixTime - it.unixTime < cacheTtl } == true
120115 }
121116 }
122117
0 commit comments