fix(ui): add TTL check for cache expiration

Add a 24-hour time-to-live check to the data cache restoration logic to prevent using stale cached data. This ensures data freshness by expiring and removing outdated cache entries before restoration. Also corrected a minor typo in the validity check comment.
This commit is contained in:
jgor20
2026-01-11 15:01:00 +00:00
parent aa1a72dc62
commit 85381f60a0

View File

@@ -50,7 +50,16 @@ document.addEventListener('alpine:init', () => {
const cached = localStorage.getItem('ag_data_cache'); const cached = localStorage.getItem('ag_data_cache');
if (cached) { if (cached) {
const data = JSON.parse(cached); const data = JSON.parse(cached);
// Basic validty check const CACHE_TTL = 24 * 60 * 60 * 1000; // 24 hours
// Check TTL
if (data.timestamp && (Date.now() - data.timestamp > CACHE_TTL)) {
console.log('Cache expired, skipping restoration');
localStorage.removeItem('ag_data_cache');
return;
}
// Basic validity check
if (data.accounts && data.models) { if (data.accounts && data.models) {
this.accounts = data.accounts; this.accounts = data.accounts;
this.models = data.models; this.models = data.models;