diff --git a/public/src/tts-modal.js b/public/src/tts-modal.js index 98869e1..45358e3 100644 --- a/public/src/tts-modal.js +++ b/public/src/tts-modal.js @@ -9,20 +9,30 @@ async function populateVoiceDropdown(voiceSelection) { // Check cache first (1 minute expiration) const cacheKey = 'uncloseai_voices_cache'; const cacheTimeKey = 'uncloseai_voices_cache_time'; + const cacheVersionKey = 'uncloseai_voices_cache_version'; const cacheExpiration = 60000; // 1 minute in milliseconds + const currentVersion = '2'; // Increment this when voice models change try { const cachedTime = localStorage.getItem(cacheTimeKey); const cachedVoices = localStorage.getItem(cacheKey); + const cachedVersion = localStorage.getItem(cacheVersionKey); - if (cachedTime && cachedVoices) { + // Check if cache is valid (not expired AND correct version) + if (cachedTime && cachedVoices && cachedVersion === currentVersion) { const age = Date.now() - parseInt(cachedTime, 10); if (age < cacheExpiration) { - console.log('Using cached voices data'); + console.log('Using cached voices data (v' + currentVersion + ')'); const voices = JSON.parse(cachedVoices); renderVoiceOptions(voiceSelection, voices); return voices; } + } else if (cachedVersion !== currentVersion) { + console.log('Cache version mismatch - invalidating old cache'); + // Clear old cache + localStorage.removeItem(cacheKey); + localStorage.removeItem(cacheTimeKey); + localStorage.removeItem(cacheVersionKey); } } catch (error) { console.warn('Cache read failed:', error); @@ -39,10 +49,11 @@ async function populateVoiceDropdown(voiceSelection) { const data = await response.json(); - // Cache the response + // Cache the response with version try { localStorage.setItem(cacheKey, JSON.stringify(data.voices)); localStorage.setItem(cacheTimeKey, Date.now().toString()); + localStorage.setItem(cacheVersionKey, currentVersion); } catch (error) { console.warn('Cache write failed:', error); }