diff --git a/config.example.json b/config.example.json
index b26e5ac2..6774ce00 100644
--- a/config.example.json
+++ b/config.example.json
@@ -22,5 +22,26 @@
"OAK": "Oakland, US",
"MRY": "Monterey, US",
"LAR": "Los Angeles, US"
+ },
+ "cacheTTL": {
+ "stats": 10,
+ "nodeDetail": 300,
+ "nodeHealth": 300,
+ "nodeList": 90,
+ "bulkHealth": 600,
+ "networkStatus": 600,
+ "observers": 300,
+ "channels": 15,
+ "channelMessages": 10,
+ "analyticsRF": 1800,
+ "analyticsTopology": 1800,
+ "analyticsChannels": 1800,
+ "analyticsHashSizes": 3600,
+ "analyticsSubpaths": 3600,
+ "analyticsSubpathDetail": 3600,
+ "nodeAnalytics": 60,
+ "nodeSearch": 10,
+ "invalidationDebounce": 30,
+ "_comment": "All values in seconds. Server uses these directly. Client fetches via /api/config/cache."
}
}
\ No newline at end of file
diff --git a/public/analytics.js b/public/analytics.js
index 6e689f2c..6263da1c 100644
--- a/public/analytics.js
+++ b/public/analytics.js
@@ -101,10 +101,10 @@
try {
_analyticsData = {};
const [hashData, rfData, topoData, chanData] = await Promise.all([
- api('/analytics/hash-sizes', { ttl: 300000 }),
- api('/analytics/rf', { ttl: 300000 }),
- api('/analytics/topology', { ttl: 300000 }),
- api('/analytics/channels', { ttl: 300000 }),
+ api('/analytics/hash-sizes', { ttl: CLIENT_TTL.analyticsRF }),
+ api('/analytics/rf', { ttl: CLIENT_TTL.analyticsRF }),
+ api('/analytics/topology', { ttl: CLIENT_TTL.analyticsRF }),
+ api('/analytics/channels', { ttl: CLIENT_TTL.analyticsRF }),
]);
_analyticsData = { hashData, rfData, topoData, chanData };
renderTab('overview');
@@ -747,7 +747,7 @@
`;
let allNodes = [];
- try { const nd = await api('/nodes?limit=2000', { ttl: 90000 }); allNodes = nd.nodes || []; } catch {}
+ try { const nd = await api('/nodes?limit=2000', { ttl: CLIENT_TTL.nodeList }); allNodes = nd.nodes || []; } catch {}
renderHashMatrix(data.topHops, allNodes);
renderCollisions(data.topHops, allNodes);
}
@@ -938,10 +938,10 @@
el.innerHTML = '
Analyzing route patterns…
';
try {
const [d2, d3, d4, d5] = await Promise.all([
- api('/analytics/subpaths?minLen=2&maxLen=2&limit=50', { ttl: 300000 }),
- api('/analytics/subpaths?minLen=3&maxLen=3&limit=30', { ttl: 300000 }),
- api('/analytics/subpaths?minLen=4&maxLen=4&limit=20', { ttl: 300000 }),
- api('/analytics/subpaths?minLen=5&maxLen=8&limit=15', { ttl: 300000 })
+ api('/analytics/subpaths?minLen=2&maxLen=2&limit=50', { ttl: CLIENT_TTL.analyticsRF }),
+ api('/analytics/subpaths?minLen=3&maxLen=3&limit=30', { ttl: CLIENT_TTL.analyticsRF }),
+ api('/analytics/subpaths?minLen=4&maxLen=4&limit=20', { ttl: CLIENT_TTL.analyticsRF }),
+ api('/analytics/subpaths?minLen=5&maxLen=8&limit=15', { ttl: CLIENT_TTL.analyticsRF })
]);
function renderTable(data, title) {
@@ -1032,7 +1032,7 @@
panel.classList.remove('collapsed');
panel.innerHTML = 'Loading…
';
try {
- const data = await api('/analytics/subpath-detail?hops=' + encodeURIComponent(hopsStr), { ttl: 300000 });
+ const data = await api('/analytics/subpath-detail?hops=' + encodeURIComponent(hopsStr), { ttl: CLIENT_TTL.analyticsRF });
renderSubpathDetail(panel, data);
} catch (e) {
panel.innerHTML = `Error: ${e.message}
`;
@@ -1141,9 +1141,9 @@
el.innerHTML = 'Loading node analytics…
';
try {
const [nodesResp, bulkHealth, netStatus] = await Promise.all([
- api('/nodes?limit=200&sortBy=lastSeen', { ttl: 90000 }),
- api('/nodes/bulk-health?limit=50', { ttl: 300000 }),
- api('/nodes/network-status', { ttl: 300000 })
+ api('/nodes?limit=200&sortBy=lastSeen', { ttl: CLIENT_TTL.nodeList }),
+ api('/nodes/bulk-health?limit=50', { ttl: CLIENT_TTL.analyticsRF }),
+ api('/nodes/network-status', { ttl: CLIENT_TTL.analyticsRF })
]);
const nodes = nodesResp.nodes || nodesResp;
const myNodes = JSON.parse(localStorage.getItem('meshcore-my-nodes') || '[]');
diff --git a/public/app.js b/public/app.js
index 40a3d8cb..08d570f0 100644
--- a/public/app.js
+++ b/public/app.js
@@ -14,6 +14,21 @@ function payloadTypeColor(n) { return PAYLOAD_COLORS[n] || 'unknown'; }
const _apiPerf = { calls: 0, totalMs: 0, log: [], cacheHits: 0 };
const _apiCache = new Map();
const _inflight = new Map();
+// Client-side TTLs (ms) — loaded from server config, with defaults
+const CLIENT_TTL = {
+ stats: 10000, nodeDetail: 240000, nodeHealth: 240000, nodeList: 90000,
+ bulkHealth: 300000, networkStatus: 300000, observers: 120000,
+ channels: 15000, channelMessages: 10000, analyticsRF: 300000,
+ analyticsTopology: 300000, analyticsChannels: 300000, analyticsHashSizes: 300000,
+ analyticsSubpaths: 300000, analyticsSubpathDetail: 300000,
+ nodeAnalytics: 60000, nodeSearch: 10000
+};
+// Fetch server cache config and use as client TTLs (server values are in seconds)
+fetch('/api/config/cache').then(r => r.json()).then(cfg => {
+ for (const [k, v] of Object.entries(cfg)) {
+ if (k in CLIENT_TTL && typeof v === 'number') CLIENT_TTL[k] = v * 1000;
+ }
+}).catch(() => {});
async function api(path, { ttl = 0, bust = false } = {}) {
const t0 = performance.now();
if (!bust && ttl > 0) {
@@ -356,7 +371,7 @@ window.addEventListener('DOMContentLoaded', () => {
favDropdown.innerHTML = 'Loading...
';
const items = await Promise.all(favs.map(async (pk) => {
try {
- const h = await api('/nodes/' + pk + '/health', { ttl: 240000 });
+ const h = await api('/nodes/' + pk + '/health', { ttl: CLIENT_TTL.nodeHealth });
const age = h.stats.lastHeard ? Date.now() - new Date(h.stats.lastHeard).getTime() : null;
const status = age === null ? '🔴' : age < 3600000 ? '🟢' : age < 86400000 ? '🟡' : '🔴';
return ''
@@ -460,7 +475,7 @@ window.addEventListener('DOMContentLoaded', () => {
// --- Nav Stats ---
async function updateNavStats() {
try {
- const stats = await api('/stats', { ttl: 10000 });
+ const stats = await api('/stats', { ttl: CLIENT_TTL.stats });
const el = document.getElementById('navStats');
if (el) {
el.innerHTML = `${stats.totalPackets} pkts · ${stats.totalNodes} nodes · ${stats.totalObservers} obs`;
diff --git a/public/channels.js b/public/channels.js
index a791def2..5731a9d8 100644
--- a/public/channels.js
+++ b/public/channels.js
@@ -18,7 +18,7 @@
if (cached && !cached.fetchedAt) return cached; // legacy null entries
}
try {
- const data = await api('/nodes/search?q=' + encodeURIComponent(name), { ttl: 10000 });
+ const data = await api('/nodes/search?q=' + encodeURIComponent(name), { ttl: CLIENT_TTL.channelMessages });
// Try exact match first, then case-insensitive, then contains
const nodes = data.nodes || [];
const match = nodes.find(n => n.name === name)
@@ -110,7 +110,7 @@
}
try {
- const detail = await api('/nodes/' + encodeURIComponent(node.public_key), { ttl: 240000 });
+ const detail = await api('/nodes/' + encodeURIComponent(node.public_key), { ttl: CLIENT_TTL.nodeDetail });
const n = detail.node;
const adverts = detail.recentAdverts || [];
const role = n.is_repeater ? '📡 Repeater' : n.is_room ? '🏠 Room' : n.is_sensor ? '🌡 Sensor' : '📻 Companion';
@@ -389,7 +389,7 @@
async function loadChannels(silent) {
try {
- const data = await api('/channels', { ttl: 15000 });
+ const data = await api('/channels', { ttl: CLIENT_TTL.channels });
channels = (data.channels || []).sort((a, b) => (b.lastActivity || '').localeCompare(a.lastActivity || ''));
renderChannelList();
} catch (e) {
@@ -451,7 +451,7 @@
msgEl.innerHTML = 'Loading messages…
';
try {
- const data = await api(`/channels/${hash}/messages?limit=200`, { ttl: 10000 });
+ const data = await api(`/channels/${hash}/messages?limit=200`, { ttl: CLIENT_TTL.channelMessages });
messages = data.messages || [];
renderMessages();
scrollToBottom();
@@ -466,7 +466,7 @@
if (!msgEl) return;
const wasAtBottom = msgEl.scrollHeight - msgEl.scrollTop - msgEl.clientHeight < 60;
try {
- const data = await api(`/channels/${selectedHash}/messages?limit=200`, { ttl: 10000 });
+ const data = await api(`/channels/${selectedHash}/messages?limit=200`, { ttl: CLIENT_TTL.channelMessages });
const newMsgs = data.messages || [];
// #92: Use message ID/hash for change detection instead of count + timestamp
var _getLastId = function (arr) { var m = arr.length ? arr[arr.length - 1] : null; return m ? (m.id || m.packetId || m.timestamp || '') : ''; };
diff --git a/public/home.js b/public/home.js
index 98dd51a1..c3d5bac7 100644
--- a/public/home.js
+++ b/public/home.js
@@ -146,7 +146,7 @@
if (!q) { suggest.classList.remove('open'); input.setAttribute('aria-expanded', 'false'); input.setAttribute('aria-activedescendant', ''); return; }
searchTimeout = setTimeout(async () => {
try {
- const data = await api('/nodes/search?q=' + encodeURIComponent(q), { ttl: 10000 });
+ const data = await api('/nodes/search?q=' + encodeURIComponent(q), { ttl: CLIENT_TTL.nodeSearch });
const nodes = data.nodes || [];
if (!nodes.length) {
suggest.innerHTML = 'No nodes found
';
@@ -247,7 +247,7 @@
const cards = await Promise.all(myNodes.map(async (mn) => {
try {
- const h = await api('/nodes/' + encodeURIComponent(mn.pubkey) + '/health', { ttl: 240000 });
+ const h = await api('/nodes/' + encodeURIComponent(mn.pubkey) + '/health', { ttl: CLIENT_TTL.nodeHealth });
const node = h.node || {};
const stats = h.stats || {};
const obs = h.observers || [];
@@ -369,7 +369,7 @@
// ==================== STATS ====================
async function loadStats() {
try {
- const s = await api('/stats', { ttl: 10000 });
+ const s = await api('/stats', { ttl: CLIENT_TTL.nodeSearch });
const el = document.getElementById('homeStats');
if (!el) return;
el.innerHTML = `
@@ -391,7 +391,7 @@
if (journey) journey.classList.remove('visible');
try {
- const h = await api('/nodes/' + encodeURIComponent(pubkey) + '/health', { ttl: 240000 });
+ const h = await api('/nodes/' + encodeURIComponent(pubkey) + '/health', { ttl: CLIENT_TTL.nodeHealth });
const node = h.node || {};
const stats = h.stats || {};
const packets = h.recentPackets || [];
diff --git a/public/index.html b/public/index.html
index 32b5a90c..ea4c1657 100644
--- a/public/index.html
+++ b/public/index.html
@@ -76,17 +76,17 @@
-
-
-
-
-
-
+
+
+
+
+
+
-
+
-
-
+
+