Skip to content

Commit b5b0bcc

Browse files
committed
work on stale cache #1554
1 parent 2771a6e commit b5b0bcc

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

front/deviceDetails.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ function updateChevrons(currentMac) {
299299

300300
showSpinner();
301301

302-
cacheDevices().then(() => {
302+
cacheDevices(true).then(() => {
303303
hideSpinner();
304304

305305
// Retry after re-caching
@@ -507,7 +507,7 @@ function updateDevicePageName(mac) {
507507
if (mac != 'new' && (name === null|| owner === null)) {
508508
console.warn("Device not found in cache, retrying after re-cache:", mac);
509509
showSpinner();
510-
cacheDevices().then(() => {
510+
cacheDevices(true).then(() => {
511511
hideSpinner();
512512
// Retry after successful cache
513513
updateDevicePageName(mac);

front/js/cache.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,23 @@ function getDevDataByMac(macAddress, dbColumn) {
451451
}
452452

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

0 commit comments

Comments
 (0)