| |
| |
| |
|
|
| import type { AnalysisResult } from '../types/analysis.types.ts'; |
| import type { MCPTool } from '../types/mcp.types.ts'; |
|
|
| const CACHE_KEY = 'analysis_data_cache'; |
| const CACHE_TIMESTAMP_KEY = 'analysis_data_cache_timestamp'; |
|
|
| const MCP_TOOLS_CACHE_KEY = 'mcp_tools_cache'; |
| const MCP_TOOLS_CACHE_TIMESTAMP_KEY = 'mcp_tools_cache_timestamp'; |
|
|
| type CachedAnalysisData = { |
| results: AnalysisResult[]; |
| timestamp: number; |
| }; |
|
|
| type CachedMCPToolsData = { |
| tools: MCPTool[]; |
| timestamp: number; |
| }; |
|
|
| |
| |
| |
| export function cacheAnalysisData(results: AnalysisResult[]): void { |
| try { |
| const cacheData: CachedAnalysisData = { |
| results, |
| timestamp: Date.now(), |
| }; |
| localStorage.setItem(CACHE_KEY, JSON.stringify(cacheData)); |
| localStorage.setItem(CACHE_TIMESTAMP_KEY, String(cacheData.timestamp)); |
| } catch (error) { |
| |
| console.warn('Failed to cache analysis data:', error); |
| } |
| } |
|
|
| |
| |
| |
| export function getCachedAnalysisData(): AnalysisResult[] | null { |
| try { |
| const cached = localStorage.getItem(CACHE_KEY); |
| if (!cached) return null; |
|
|
| const cacheData: CachedAnalysisData = JSON.parse(cached); |
| return cacheData.results; |
| } catch (error) { |
| |
| console.warn('Failed to retrieve cached analysis data:', error); |
| return null; |
| } |
| } |
|
|
| |
| |
| |
| export function getCacheTimestamp(): number | null { |
| try { |
| const timestamp = localStorage.getItem(CACHE_TIMESTAMP_KEY); |
| return timestamp ? Number(timestamp) : null; |
| } catch (error) { |
| return null; |
| } |
| } |
|
|
| |
| |
| |
| export function clearAnalysisCache(): void { |
| try { |
| localStorage.removeItem(CACHE_KEY); |
| localStorage.removeItem(CACHE_TIMESTAMP_KEY); |
| } catch (error) { |
| console.warn('Failed to clear analysis cache:', error); |
| } |
| } |
|
|
| export function cacheMcpTools(tools: MCPTool[]): void { |
| try { |
| const cacheData: CachedMCPToolsData = { |
| tools, |
| timestamp: Date.now(), |
| }; |
| localStorage.setItem(MCP_TOOLS_CACHE_KEY, JSON.stringify(cacheData)); |
| localStorage.setItem( |
| MCP_TOOLS_CACHE_TIMESTAMP_KEY, |
| String(cacheData.timestamp) |
| ); |
| } catch (error) { |
| console.warn('Failed to cache MCP tools:', error); |
| } |
| } |
|
|
| export function getCachedMcpTools(): MCPTool[] | null { |
| try { |
| const cached = localStorage.getItem(MCP_TOOLS_CACHE_KEY); |
| if (!cached) return null; |
|
|
| const cacheData: CachedMCPToolsData = JSON.parse(cached); |
| return cacheData.tools; |
| } catch (error) { |
| console.warn('Failed to retrieve cached MCP tools:', error); |
| return null; |
| } |
| } |
|
|
| export function clearMcpToolsCache(): void { |
| try { |
| localStorage.removeItem(MCP_TOOLS_CACHE_KEY); |
| localStorage.removeItem(MCP_TOOLS_CACHE_TIMESTAMP_KEY); |
| } catch (error) { |
| console.warn('Failed to clear MCP tools cache:', error); |
| } |
| } |
|
|
| |
| |
| |
| export function cacheRecentAnalysisData(results: AnalysisResult[]): void { |
| try { |
| const cacheData: CachedAnalysisData = { |
| results, |
| timestamp: Date.now(), |
| }; |
| localStorage.setItem('recent_analysis_data_cache', JSON.stringify(cacheData)); |
| } catch (error) { |
| |
| console.warn('Failed to cache recent analysis data:', error); |
| } |
| } |
|
|
| |
| |
| |
| export function getCachedRecentAnalysisData(): AnalysisResult[] | null { |
| try { |
| const cached = localStorage.getItem('recent_analysis_data_cache'); |
| if (!cached) return null; |
|
|
| const cacheData: CachedAnalysisData = JSON.parse(cached); |
| return cacheData.results; |
| } catch (error) { |
| |
| console.warn('Failed to retrieve cached recent analysis data:', error); |
| return null; |
| } |
| } |
|
|
|
|