// src/services/query-cache.js const queries = new Map(); export const queryCache = { /** * Get cached query result * @param {string} queryId - Query identifier (e.g., "timeline", "profile:handle") * @returns {{ uris: string[], cursor: string|null, hasMore: boolean }|undefined} */ get(queryId) { return queries.get(queryId); }, /** * Set query result (replaces existing) * @param {string} queryId - Query identifier * @param {{ uris: string[], cursor: string|null, hasMore: boolean }} result */ set(queryId, result) { queries.set(queryId, { uris: result.uris || [], cursor: result.cursor || null, hasMore: result.hasMore ?? true, fetchedAt: Date.now() }); }, /** * Append to existing query result (for pagination) * @param {string} queryId - Query identifier * @param {{ uris: string[], cursor: string|null, hasMore: boolean }} result */ append(queryId, result) { const existing = queries.get(queryId); if (existing) { queries.set(queryId, { uris: [...existing.uris, ...(result.uris || [])], cursor: result.cursor || null, hasMore: result.hasMore ?? true, fetchedAt: existing.fetchedAt // preserve original fetch time }); } else { this.set(queryId, result); } }, /** * Check if query is cached * @param {string} queryId - Query identifier * @returns {boolean} */ has(queryId) { return queries.has(queryId); }, /** * Clear all query cache (useful for logout or refresh) */ clear() { queries.clear(); } };