Skip to content

Commit

Permalink
Add optional timeout when checking disk cache in Vito for SF
Browse files Browse the repository at this point in the history
Reviewed By: oprisnik

Differential Revision: D65206058

fbshipit-source-id: 0542c62a43f9f196487d3794fbec2d3029e0af72
  • Loading branch information
Artem Kholodnyi authored and facebook-github-bot committed Oct 30, 2024
1 parent c06fc9f commit 2535bb3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class VitoImagePipelineImpl(
timeout: Long,
unit: TimeUnit
): Boolean {
if (timeout <= 0) {
return isInDiskCacheSync(vitoImageRequest)
}
val imageRequest = vitoImageRequest.finalImageRequest ?: return false
return try {
DataSources.waitForFinalResult(imagePipeline.isInDiskCache(imageRequest), timeout, unit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ constructor(override val prefetchConfig: PrefetchConfig = DefaultPrefetchConfig(

override fun experimentalDynamicSizeOnPrepareMainThreadVito2(): Boolean = false

override fun experimentalDynamicSizeDiskCacheCheckTimeoutMs(): Long = 0

open class DefaultPrefetchConfig : PrefetchConfig {
override fun prefetchInOnPrepare(): Boolean = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ interface FrescoVitoConfig {
fun experimentalDynamicSizeWithCacheFallbackVito2(): Boolean

fun experimentalDynamicSizeOnPrepareMainThreadVito2(): Boolean

fun experimentalDynamicSizeDiskCacheCheckTimeoutMs(): Long
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import com.facebook.litho.annotations.ShouldExcludeFromIncrementalMount
import com.facebook.litho.annotations.ShouldUpdate
import com.facebook.litho.annotations.TreeProp
import com.facebook.litho.utils.MeasureUtils
import java.util.concurrent.TimeUnit

/** Fresco Vito component for Litho */
@MountSpec(isPureRender = true, canPreallocate = true, poolSize = 15)
Expand Down Expand Up @@ -171,7 +172,11 @@ object FrescoVitoImage2Spec {
forceKeepOriginalSize.set(!experimentalDynamicSizeOnPrepareMainThreadVito2())
} else {
forceKeepOriginalSize.set(
FrescoVitoProvider.getImagePipeline().isInDiskCacheSync(requestCachedValue))
FrescoVitoProvider.getImagePipeline()
.isInDiskCacheSync(
requestCachedValue,
FrescoVitoProvider.getConfig().experimentalDynamicSizeDiskCacheCheckTimeoutMs(),
TimeUnit.MILLISECONDS))
}
if (forceKeepOriginalSize.get() == true) {
// Prefetch in OnPrepare since no prefetch will happen in OnBoundsDefined
Expand Down

0 comments on commit 2535bb3

Please sign in to comment.