{"record":{"id":"f3fe917bf670c697","repo":"davila7/claude-code-templates","slug":"failed-to-clear-cache","errorCode":null,"errorMessage":"Failed to clear cache","messagePattern":"Failed to clear cache","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"cli-tool/src/analytics.js","lineNumber":1183,"sourceCode":"        \n        if (!type || type === 'all') {\n          // Clear all caches\n          this.dataCache.invalidateComputations();\n          this.dataCache.caches.parsedConversations.clear();\n          this.dataCache.caches.fileContent.clear();\n          this.dataCache.caches.fileStats.clear();\n          res.json({ success: true, message: 'All caches cleared' });\n        } else if (type === 'conversations') {\n          // Clear only conversation-related caches\n          this.dataCache.caches.parsedConversations.clear();\n          this.dataCache.caches.fileContent.clear();\n          res.json({ success: true, message: 'Conversation caches cleared' });\n        } else {\n          res.status(400).json({ error: 'Invalid cache type. Use \"all\" or \"conversations\"' });\n        }\n      } catch (error) {\n        console.error('Error clearing cache:', error);\n        res.status(500).json({ error: 'Failed to clear cache' });\n      }\n    });\n\n    // Clear cache endpoint\n    this.app.post('/api/clear-cache', async (req, res) => {\n      try {\n        console.log('🔥 Clear cache request received');\n        \n        // Clear DataCache\n        if (this.dataCache && typeof this.dataCache.clear === 'function') {\n          this.dataCache.clear();\n          console.log('🔥 Server DataCache cleared');\n        } else {\n          console.log('⚠️ DataCache not available or no clear method');\n        }\n        \n        // Also clear ConversationAnalyzer cache if available\n        if (this.conversationAnalyzer && typeof this.conversationAnalyzer.clearCache === 'function') {","sourceCodeStart":1165,"sourceCodeEnd":1201,"githubUrl":"https://github.com/davila7/claude-code-templates/blob/a0851ed10c7c60463dac8cfaaca124cf32d5804d/cli-tool/src/analytics.js#L1165-L1201","documentation":"500 from the first cache-clear endpoint (the one with the ?type= parameter). After validating the type, the actual cache .clear() calls threw — e.g. this.dataCache.caches being undefined because the cache layer wasn't initialized.","triggerScenarios":"POST /api/clear-cache?type=all|conversations when dataCache or one of its internal Map caches is undefined, or a clear() call fails mid-iteration.","commonSituations":"Endpoint hit during server startup before caches exist; version mismatch between the route and the cache implementation after a partial upgrade.","solutions":["Check the console line 'Error clearing cache:' for the true cause","Restart the analytics server so the cache layer initializes fully","Verify this.dataCache.caches.parsedConversations/fileContent exist in your version","Upgrade the CLI package so route and cache code are in sync"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"await fetch(base + '/api/system-health').then(r => { if (!r.ok) throw new Error('cache layer not ready'); });","typeGuard":null,"tryCatchPattern":"try { await clearCache('all'); } catch { await restartAnalyticsServer(); await clearCache('all'); }","preventionTips":["Only clear caches after the server signals ready","Don't clear caches during an active analytics scan"],"tags":["analytics","express","http-500","cache"],"backgroundTag":"cache-invalidation-failure","analyzedSha":"a0851ed10c7c60463dac8cfaaca124cf32d5804d","analyzedAt":"2026-08-28T14:11:56.058Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}