diff --git a/data/loader.js b/data/loader.js index 36769ff..e3be078 100644 --- a/data/loader.js +++ b/data/loader.js @@ -100,7 +100,7 @@ config.fullscreenOnLoad = window.EJS_fullscreenOnLoaded; config.filePaths = window.EJS_paths; config.loadState = window.EJS_loadStateURL; - config.cacheLimit = window.EJS_CacheLimit; + config.cacheConfig = window.EJS_cacheConfig; config.cheats = window.EJS_cheats; config.defaultOptions = window.EJS_defaultOptions; config.gamePatchUrl = window.EJS_gamePatchUrl; @@ -120,7 +120,6 @@ config.externalFiles = window.EJS_externalFiles; config.dontExtractRom = window.EJS_dontExtractRom; config.dontExtractBIOS = window.EJS_dontExtractBIOS; - config.disableDatabases = window.EJS_disableDatabases; config.disableLocalStorage = window.EJS_disableLocalStorage; config.forceLegacyCores = window.EJS_forceLegacyCores; config.noAutoFocus = window.EJS_noAutoFocus; diff --git a/data/src/emulator.js b/data/src/emulator.js index 3e490c3..bfa4cce 100644 --- a/data/src/emulator.js +++ b/data/src/emulator.js @@ -328,26 +328,47 @@ class EmulatorJS { return null; })(); this.isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); - if (this.config.disableDatabases) { - this.storage = { - // Remove rom and bios storage - rely on browser cache for files and checkCompression for decompression - } - this.storageCache = new window.EJS_Cache(false, new window.EJS_DUMMYSTORAGE(), new window.EJS_DUMMYSTORAGE(), 1, 1, this.debug); - } else { - this.storage = { - // Remove rom and bios storage - rely on browser cache for files and checkCompression for decompression - } - this.storageCache = new window.EJS_Cache(true, new window.EJS_STORAGE("EmulatorJS-cache", "cache"), new window.EJS_STORAGE("EmulatorJS-cacheBlobs", "cacheblobs"), this.config.cacheMaxSizeMB || 4096, this.config.cacheMaxAgeMins || 7200, this.debug); - // Run initial cleanup after cache initialization (non-blocking) - setTimeout(async () => { - try { - await this.storageCache.cleanup(); - } catch (error) { - console.error('[EJS Cache] Error during startup cleanup:', error); - } - }, 5000); // 5 second delay to avoid blocking startup + this.storage = {} + + // set cache configuration defaults + const cacheConfigDefaults = { + enabled: true, + cacheMaxSizeMB: 4096, + cacheMaxAgeMins: 7200 + }; + // Overwrite invalid or missing values in this.config.cacheConfig with defaults + if (!this.config.cacheConfig || typeof this.config.cacheConfig !== "object") { + this.config.cacheConfig = {}; } + if (typeof this.config.cacheConfig.enabled !== "boolean") { + this.config.cacheConfig.enabled = cacheConfigDefaults.enabled; + } + if (typeof this.config.cacheConfig.cacheMaxSizeMB !== "number" || this.config.cacheConfig.cacheMaxSizeMB <= 0) { + this.config.cacheConfig.cacheMaxSizeMB = cacheConfigDefaults.cacheMaxSizeMB; + } + if (typeof this.config.cacheConfig.cacheMaxAgeMins !== "number" || this.config.cacheConfig.cacheMaxAgeMins <= 0) { + this.config.cacheConfig.cacheMaxAgeMins = cacheConfigDefaults.cacheMaxAgeMins; + } + + this.storageCache = new window.EJS_Cache( + this.config.cacheConfig.enabled, + new window.EJS_STORAGE("EmulatorJS-cache", "cache"), + new window.EJS_STORAGE("EmulatorJS-cacheBlobs", "cacheblobs"), + this.config.cacheConfig.cacheMaxSizeMB, + this.config.cacheConfig.cacheMaxAgeMins || 7200, + this.debug + ); + + // Run initial cleanup after cache initialization (non-blocking) + setTimeout(async () => { + try { + await this.storageCache.cleanup(); + } catch (error) { + console.error('[EJS Cache] Error during startup cleanup:', error); + } + }, 5000); // 5 second delay to avoid blocking startup + // This is not cache. This is save data this.storage.states = new window.EJS_STORAGE("EmulatorJS-states", "states"); @@ -2175,7 +2196,7 @@ class EmulatorJS { this.openCacheMenu(); }); - if (this.config.disableDatabases) cache.style.display = "none"; + if (this.config.cacheConfig.enabled === false) cache.style.display = "none"; let savUrl; diff --git a/index.html b/index.html index ba4c080..fe3a3e2 100644 --- a/index.html +++ b/index.html @@ -257,11 +257,15 @@ window.EJS_pathtodata = "data/"; window.EJS_startOnLoaded = true; window.EJS_DEBUG_XX = enableDebug; - window.EJS_disableDatabases = false; window.EJS_threads = enableThreads; if (browserMode) { window.EJS_browserMode = browserMode; } + window.EJS_cacheConfig = { + enabled: true, + cacheMaxSizeMB: 4096, + cacheMaxAgeMins: 7200 + }; script.src = "data/loader.js"; document.body.appendChild(script);