f0e12555bca2d035cbd2d80414e2d4e154543f9b jcasper Fri Mar 13 18:12:59 2026 -0700 Removing local storage cache in facetedComposite.js - it's too easy to reach the storage limit, and the browser's own file cache should mostly satisfy this need. We'll work next on adding a forced refresh when udcTimeout is set in the cart, to facilitate development, refs #36320 diff --git src/hg/js/facetedComposite.js src/hg/js/facetedComposite.js index 45eb5485348..f67cf572547 100644 --- src/hg/js/facetedComposite.js +++ src/hg/js/facetedComposite.js @@ -417,82 +417,52 @@ // No ${mdid}.dt* variables indicates that the composite doesn't use data types updateVisibilities(uriForUpdate, submitBtnEvent); }); } // end initSubmit function initAll(dataForTable) { initDataTypeSelector(); const table = initTable(dataForTable); initFilters(table, dataForTable); initSubmit(table); } function loadDataAndInit() { // load data and call init functions const { mdid, primaryKey, metadataUrl, colorSettingsUrl } = embeddedData; - - const CACHE_KEY = mdid; - const CACHE_TIMESTAMP = `${CACHE_KEY}_time_stamp`; - const CACHE_EXPIRY_MS = 24 * 60 * 60 * 1000; // 24 hours - - const now = Date.now(); - const cachedTime = parseInt(localStorage.getItem(CACHE_TIMESTAMP), 10); - - let cachedData = null; - let useCache = false; - - if (cachedTime && (now - cachedTime < CACHE_EXPIRY_MS)) { - const cachedStr = localStorage.getItem(CACHE_KEY); - cachedData = cachedStr ? JSON.parse(cachedStr) : null; - useCache = !!cachedData; - } - - if (useCache) { - initAll(cachedData); - return; - } - fetch(metadataUrl) .then(response => { if (!response.ok) { // a 404 will look like plain text throw new Error(`HTTP Status: ${response.status}`); } return response.text(); }) .then(tsvText => { // metadata table is a TSV file to parse loadOptional(colorSettingsUrl).then(colorMap => { const rows = tsvText.trim().split("\n"); const colNames = rows[0].split("\t"); const metadata = rows.slice(1).map(row => { const values = row.split("\t"); const obj = {}; colNames.forEach((attrib, i) => { obj[attrib] = values[i]; }); return obj; }); - if (!metadata.length || !colNames.length) { - localStorage.removeItem(CACHE_KEY); - localStorage.removeItem(CACHE_TIMESTAMP); - return; - } const rowToIdx = Object.fromEntries( metadata.map((row, i) => [row[primaryKey], i]) ); colorMap = isValidColorMap(colorMap) ? colorMap : null; const freshData = { metadata, rowToIdx, colNames, colorMap }; - // cache the data - localStorage.setItem(CACHE_KEY, JSON.stringify(freshData)); - localStorage.setItem(CACHE_TIMESTAMP, now.toString()); initAll(freshData); }); }); } // end loadDataAndInit CSS_URLS.map(href => // load all the CSS document.head.appendChild(Object.assign( document.createElement("link"), { rel: "stylesheet", href }))); document.addEventListener("keydown", e => { // block accidental submit if (e.key === "Enter") { e.preventDefault(); e.stopPropagation(); } }, true); // ADS: only load plugins if they are not already loaded