mirror of
https://github.com/tiennm99/loldle.git
synced 2026-10-11 12:19:08 +00:00
feat: clear expired daily game cache from localStorage on app load
This commit is contained in:
1 parent
e502d43a9c
commit
31d7127396
2 files changed
+19
No files matched your search
@@ -14,6 +14,7 @@ import {
|
||||
clearUnlimitedState,
|
||||
saveUnlimitedStats,
|
||||
loadUnlimitedStats,
|
||||
clearExpiredCache,
|
||||
} from "@/lib/game-engine";
|
||||
import { compareChampions } from "@/lib/classic-mode";
|
||||
import ChampionSearch from "./champion-search";
|
||||
@@ -50,6 +51,7 @@ export default function GameBoard() {
|
||||
useEffect(() => {
|
||||
loadChampions()
|
||||
.then(() => {
|
||||
clearExpiredCache(getTodaySeed());
|
||||
initGame("daily");
|
||||
setLoading(false);
|
||||
})
|
||||
|
||||
@@ -173,6 +173,23 @@ function loadState(mode, seed) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Remove stale daily entries from localStorage (keeps only today's) */
|
||||
export function clearExpiredCache(todaySeed) {
|
||||
try {
|
||||
const todayKey = `${STORAGE_KEY_PREFIX}daily_${todaySeed}`;
|
||||
const keysToRemove = [];
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = localStorage.key(i);
|
||||
if (key && key.startsWith(`${STORAGE_KEY_PREFIX}daily_`) && key !== todayKey) {
|
||||
keysToRemove.push(key);
|
||||
}
|
||||
}
|
||||
keysToRemove.forEach((key) => localStorage.removeItem(key));
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
function getStorageKey(mode, seed) {
|
||||
if (mode === "daily") return `${STORAGE_KEY_PREFIX}daily_${seed}`;
|
||||
return `${STORAGE_KEY_PREFIX}unlimited_current`;
|
||||
|
||||
Reference in new issue
Block a user