Prefetch fresh video thumbnail before swapping it into info view

This commit is contained in:
Arkadiusz Fal
2026-04-23 18:37:19 +02:00
parent 6eb215f59c
commit fd0eab7784
2 changed files with 32 additions and 0 deletions

View File

@@ -81,6 +81,22 @@ final class ImageLoadingService: Sendable {
)
}
/// Warm the image cache for the given URL so a subsequent `LazyImage`
/// display hits the cache instantly. Returns after the image is cached
/// or the operation fails (silently). Bounded by `timeout` seconds.
nonisolated func prefetchImage(for url: URL, timeout: TimeInterval = 3) async {
await withTaskGroup(of: Void.self) { group in
group.addTask {
_ = try? await ImagePipeline.shared.image(for: url)
}
group.addTask {
try? await Task.sleep(nanoseconds: UInt64(timeout * 1_000_000_000))
}
await group.next()
group.cancelAll()
}
}
/// Remove a specific URL from both the memory and disk image caches.
/// Use when a previously cached URL is known to return stale or broken
/// data (e.g. an expired proxied thumbnail URL).