davila7/claude-code-templates · error

Failed to clear cache

Error message

Failed to clear cache

What it means

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.

Source

Thrown at cli-tool/src/analytics.js:1183

        
        if (!type || type === 'all') {
          // Clear all caches
          this.dataCache.invalidateComputations();
          this.dataCache.caches.parsedConversations.clear();
          this.dataCache.caches.fileContent.clear();
          this.dataCache.caches.fileStats.clear();
          res.json({ success: true, message: 'All caches cleared' });
        } else if (type === 'conversations') {
          // Clear only conversation-related caches
          this.dataCache.caches.parsedConversations.clear();
          this.dataCache.caches.fileContent.clear();
          res.json({ success: true, message: 'Conversation caches cleared' });
        } else {
          res.status(400).json({ error: 'Invalid cache type. Use "all" or "conversations"' });
        }
      } catch (error) {
        console.error('Error clearing cache:', error);
        res.status(500).json({ error: 'Failed to clear cache' });
      }
    });

    // Clear cache endpoint
    this.app.post('/api/clear-cache', async (req, res) => {
      try {
        console.log('🔥 Clear cache request received');
        
        // Clear DataCache
        if (this.dataCache && typeof this.dataCache.clear === 'function') {
          this.dataCache.clear();
          console.log('🔥 Server DataCache cleared');
        } else {
          console.log('⚠️ DataCache not available or no clear method');
        }
        
        // Also clear ConversationAnalyzer cache if available
        if (this.conversationAnalyzer && typeof this.conversationAnalyzer.clearCache === 'function') {

View on GitHub (pinned to a0851ed10c)

Solutions

  1. Check the console line 'Error clearing cache:' for the true cause
  2. Restart the analytics server so the cache layer initializes fully
  3. Verify this.dataCache.caches.parsedConversations/fileContent exist in your version
  4. Upgrade the CLI package so route and cache code are in sync
Defensive patterns

Strategy: retry

Validate before calling

await fetch(base + '/api/system-health').then(r => { if (!r.ok) throw new Error('cache layer not ready'); });

Try / catch

try { await clearCache('all'); } catch { await restartAnalyticsServer(); await clearCache('all'); }

Prevention

When it happens

Trigger: 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.

Common situations: Endpoint hit during server startup before caches exist; version mismatch between the route and the cache implementation after a partial upgrade.

Related errors


AI-assisted analysis of davila7/claude-code-templates@a0851ed10c (2026-08-28). Data as JSON: /api/errors/f3fe917bf670c697. Report an issue: GitHub.