The match results or null if not found or incompatible version.
export function getSavedMatchResults(): MatchResult[] | null {
try {
console.debug("[Storage] 🔍 Retrieving saved match results...");
// Check cache version compatibility
const savedVersion = Number.parseInt(
storage.getItem(STORAGE_KEYS.CACHE_VERSION) || "0",
10,
);
if (savedVersion !== CURRENT_CACHE_VERSION && savedVersion !== 0) {
console.warn(
`[Storage] ⚠️ Cache version mismatch. Saved: ${savedVersion}, Current: ${CURRENT_CACHE_VERSION}`,
);
return null; // Consider the cache invalid if versions don't match
}
const savedResults = storage.getItem(STORAGE_KEYS.MATCH_RESULTS);
if (savedResults) {
const parsed = JSON.parse(savedResults);
console.info(`[Storage] ✅ Retrieved ${parsed.length} match results`);
return parsed;
}
console.debug("[Storage] 🔍 No match results found");
return null;
} catch (error) {
captureError(
ErrorType.STORAGE,
"Error parsing saved match results",
error instanceof Error ? error : new Error(String(error)),
{
operation: "read-match-results",
isParseError: error instanceof SyntaxError,
},
);
return null;
}
}
Retrieves saved match results with cache version check.