From f3d825278ae4fdac0e951ffa991b0f52704bf809 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Mon, 10 Nov 2025 04:07:53 -0500 Subject: [PATCH] Add version-based cache invalidation for voice data Users with old cached voice data need to see the new models (tts-1-silero, tts-1-kokoro). Added a cache version system that automatically invalidates old cache when we update the voice models. Changes: - Added cacheVersionKey to track cache format version - Set currentVersion to '2' (increment when voice models change) - Cache is invalidated if version doesn't match - Old cache entries are cleaned up automatically - Users will automatically fetch fresh voice data on next modal open --- public/src/tts-modal.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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); }