chore(图片缓存系统): 添加更多执行流程的注释

This commit is contained in:
hzj 2025-12-26 20:07:22 +08:00
parent 05d4d48acc
commit 45b05d52b2

View File

@ -482,18 +482,17 @@ class ImageCacheManager {
const cachedResponse = await this.getCachedImage(normalizedSrc) // 3. 获取对应的缓存图片
// 4. 缓存命中,处理图片
if (cachedResponse) {
const blob = await cachedResponse.blob()
const imageUrl = URL.createObjectURL(blob)
const blob = await cachedResponse.blob() //将缓存响应转换为 Blob 对象
const imageUrl = URL.createObjectURL(blob) //生成临时的 Blob URL 供 Image 对象使用
const img = new Image() // 5. 创建Image对象并设置src
// 6. 加载成功清理临时URL并resolve
// 设置 onload 和 onerror 回调
img.onload = () => {
URL.revokeObjectURL(imageUrl) // 清理临时URL
resolve(img)
}
// 7. 关键:加载失败时的处理
img.onerror = () => {
URL.revokeObjectURL(imageUrl) // 8. 清理临时URL
this.loadImageFromNetwork(normalizedSrc, resolve, reject) // 9. 回退到网络加载