Skip to content

Commit 6295cb7

Browse files
committed
refactor(DeArrow): simplify cache
1 parent 6d98c98 commit 6295cb7

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

app/src/main/java/com/github/libretube/util/DeArrowUtil.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ import com.github.libretube.api.obj.Streams
88
import com.github.libretube.constants.PreferenceKeys
99
import com.github.libretube.helpers.PreferenceHelper
1010

11-
private data class CacheObject(val value: DeArrowContent?);
12-
1311
object DeArrowUtil {
14-
// we cannot use segment data directly, as LruCache expects non-null objects, but we also want to cache unlabeled videos
15-
private val memoryCache = LruCache<String, CacheObject?>(256)
12+
private val cache = LruCache<String, DeArrowContent>(256)
1613

1714
private fun extractTitleAndThumbnail(content: DeArrowContent): Pair<String?, String?> {
1815
val title = content.titles.firstOrNull { it.votes >= 0 || it.locked }?.title
@@ -26,11 +23,11 @@ object DeArrowUtil {
2623

2724
private suspend fun fetchDeArrowContent(videoId: String): DeArrowContent? {
2825
// prefer cached response, if available
29-
memoryCache.get(videoId)?.let { return it.value }
26+
cache.get(videoId)?.let { return it }
3027

3128
return try {
3229
MediaServiceRepository.instance.getDeArrowContent(videoId)
33-
.also { memoryCache.put(videoId, CacheObject(it)) }
30+
.also { cache.put(videoId, it) }
3431
} catch (e: Exception) {
3532
Log.e(this::class.java.name, "Failed to fetch DeArrow content: ${e.message}")
3633
null

0 commit comments

Comments
 (0)