[browser] make cachedResourcesPurgeDelay configurable (#90264)
authorPavel Savara <pavel.savara@gmail.com>
Thu, 10 Aug 2023 14:40:17 +0000 (16:40 +0200)
committerGitHub <noreply@github.com>
Thu, 10 Aug 2023 14:40:17 +0000 (16:40 +0200)
src/mono/wasm/runtime/dotnet.d.ts
src/mono/wasm/runtime/loader/config.ts
src/mono/wasm/runtime/startup.ts
src/mono/wasm/runtime/types/index.ts

index 2f8f000..1d5e74e 100644 (file)
@@ -130,6 +130,10 @@ type MonoConfig = {
      */
     cacheBootResources?: boolean;
     /**
+     * Delay of the purge of the cached resources in milliseconds. Default is 10000 (10 seconds).
+     */
+    cachedResourcesPurgeDelay?: number;
+    /**
      * Configures use of the `integrity` directive for fetching assets
      */
     disableIntegrityCheck?: boolean;
index dc7ba1e..c35553a 100644 (file)
@@ -181,6 +181,10 @@ export function normalizeConfig() {
         config.debugLevel = -1;
     }
 
+    if (config.cachedResourcesPurgeDelay === undefined) {
+        config.cachedResourcesPurgeDelay = 10000;
+    }
+
     // Default values (when WasmDebugLevel is not set)
     // - Build   (debug)    => debugBuild=true  & debugLevel=-1 => -1
     // - Build   (release)  => debugBuild=true  & debugLevel=0  => 0
index 3cc7317..ba49f2f 100644 (file)
@@ -269,10 +269,10 @@ async function onRuntimeInitializedAsync(userOnRuntimeInitialized: () => void) {
         if (loaderHelpers.config.debugLevel !== 0 && loaderHelpers.config.cacheBootResources) {
             loaderHelpers.logDownloadStatsToConsole();
         }
-        const afterStartupRushIsOver = 10000;// 10 seconds
+
         setTimeout(() => {
             loaderHelpers.purgeUnusedCacheEntriesAsync(); // Don't await - it's fine to run in background
-        }, afterStartupRushIsOver);
+        }, loaderHelpers.config.cachedResourcesPurgeDelay);
 
         // call user code
         try {
index 7be774e..9c0ea73 100644 (file)
@@ -64,6 +64,10 @@ export type MonoConfig = {
      */
     cacheBootResources?: boolean,
     /**
+     * Delay of the purge of the cached resources in milliseconds. Default is 10000 (10 seconds).
+     */
+    cachedResourcesPurgeDelay?: number,
+    /**
      * Configures use of the `integrity` directive for fetching assets
      */
     disableIntegrityCheck?: boolean,