Ver código fonte

优化裁切图缓存

Michael Wang 4 anos atrás
pai
commit
fc65ee2c30
1 arquivos alterados com 6 adições e 3 exclusões
  1. 6 3
      src/utils/utils.ts

+ 6 - 3
src/utils/utils.ts

@@ -103,9 +103,12 @@ function cacheFIFO() {
   if (objectUrlMap.size > OBJECT_URLS_MAP_MAX_SIZE) {
     const ary = [...objectUrlMap.entries()];
     const toRelease = ary.splice(0, 10);
-    for (const u of toRelease) {
-      URL.revokeObjectURL(u[1]);
-    }
+    // 为了避免部分图片还没显示就被revoke了,这里做一个延迟revoke
+    setTimeout(() => {
+      for (const u of toRelease) {
+        URL.revokeObjectURL(u[1]);
+      }
+    }, 2 * 6 * 1000);
     objectUrlMap = new Map(ary);
   }
 }