// Debug script to test cache behavior in detail const axios = require('axios'); const API_BASE = 'http://localhost:3001/api'; async function debugCache() { console.log('🔍 Starting cache debug session...\n'); console.log('📊 Clearing cache first:'); try { await axios.delete(`${API_BASE}/cache`); console.log('✅ Cache cleared\n'); } catch (error) { console.log(`❌ Error clearing cache: ${error.message}\n`); } console.log('📊 Making first request - should make API calls:'); const start1 = Date.now(); try { const response1 = await axios.get(`${API_BASE}/workflow-runs`); console.log(`✅ First request: ${response1.data.length} runs (${Date.now() - start1}ms)\n`); } catch (error) { console.log(`❌ First request failed: ${error.message}\n`); } console.log('📊 Waiting 2 seconds...\n'); await new Promise(resolve => setTimeout(resolve, 2000)); console.log('📊 Making second request - should hit cache:'); const start2 = Date.now(); try { const response2 = await axios.get(`${API_BASE}/workflow-runs`); console.log(`✅ Second request: ${response2.data.length} runs (${Date.now() - start2}ms)\n`); } catch (error) { console.log(`❌ Second request failed: ${error.message}\n`); } console.log('📊 Cache stats:'); try { const stats = await axios.get(`${API_BASE}/cache/stats`); console.log(`💾 Cache entries: ${stats.data.size}`); console.log(`💾 Cache keys: ${stats.data.entries.join(', ')}\n`); } catch (error) { console.log(`❌ Cache stats failed: ${error.message}\n`); } console.log('📊 Rate limit info:'); try { const rateLimit = await axios.get(`${API_BASE}/rate-limit`); console.log(`🔄 Rate limit: ${rateLimit.data.remaining}/${rateLimit.data.limit}`); } catch (error) { console.log(`❌ Rate limit failed: ${error.message}`); } } debugCache().catch(console.error);