davila7/claude-code-templates · warning
Invalid cache type. Use "all" or "conversations"
Error message
Invalid cache type. Use "all" or "conversations"
What it means
400 from the cache-clear endpoint: the ?type= query parameter was neither 'all' nor 'conversations'. This is intentional input validation, not a crash.
Source
Thrown at cli-tool/src/analytics.js:1179
this.app.post('/api/cache/clear', (req, res) => {
try {
// Clear specific cache types or all
const { type } = req.body;
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');View on GitHub (pinned to a0851ed10c)
Solutions
- Use exactly ?type=all or ?type=conversations
- Lowercase the value client-side before sending
- Update the calling code/script that hardcodes an unsupported type
Example fix
// before
await fetch(`${base}/api/clear-cache?type=messages`, { method: 'POST' });
// after
await fetch(`${base}/api/clear-cache?type=all`, { method: 'POST' }); Defensive patterns
Strategy: validation
Validate before calling
const type = ['all', 'conversations'].includes(rawType) ? rawType : 'all';
await fetch(`${base}/api/clear-cache?type=${type}`, { method: 'POST' }); Type guard
const isCacheType = (t) => t === 'all' || t === 'conversations';
Try / catch
try { ... } catch (e) { if (e.response?.status === 400) throw new Error(`bad cache type: ${sentType}`); } Prevention
- Whitelist the enum client-side
- Lowercase user-supplied type values before sending
When it happens
Trigger: POST /api/clear-cache?type=cache or any other/missing type value (empty string, 'conv', 'messages', case variants like 'ALL').
Common situations: Client code passing a wrong enum value; documentation drift where callers assume other cache names exist; case-sensitive mismatch.
Related errors
- Failed to update states
- Failed to get system health
- Failed to get Claude session info
- Failed to get performance metrics
- Failed to clear cache
AI-assisted analysis of davila7/claude-code-templates@a0851ed10c (2026-08-28).
Data as JSON: /api/errors/56a7c000e5476be6.
Report an issue: GitHub.