work on stale cache #1554

This commit is contained in:
Jokob @NetAlertX
2026-03-13 12:52:22 +00:00
parent 2771a6e9c2
commit b5b0bcc766
2 changed files with 17 additions and 5 deletions

View File

@@ -451,11 +451,23 @@ function getDevDataByMac(macAddress, dbColumn) {
}
// -----------------------------------------------------------------------------
// Cache the devices as one JSON
function cacheDevices()
/**
* Fetches the full device list from table_devices.json and stores it in
* localStorage under CACHE_KEYS.DEVICES_ALL.
*
* On subsequent calls the fetch is skipped if the initFlag is already set,
* unless forceRefresh is true. Pass forceRefresh = true whenever the caller
* knows the cached list may be stale (e.g. a device was not found by MAC and
* the page needs to recover without a full clearCache()).
*
* @param {boolean} [forceRefresh=false] - When true, bypasses the initFlag
* guard and always fetches fresh data from the server.
* @returns {Promise<void>} Resolves when the cache has been populated.
*/
function cacheDevices(forceRefresh = false)
{
return new Promise((resolve, reject) => {
if(getCache(CACHE_KEYS.initFlag('cacheDevices')) === "true")
if(!forceRefresh && getCache(CACHE_KEYS.initFlag('cacheDevices')) === "true")
{
// One-time migration: normalize legacy { data: [...] } wrapper to a plain array.
// Old cache entries from prior versions stored the raw API envelope; re-write