clear_cache
Clear stored data cache in Metabase to resolve outdated information issues. Supports targeted clearing for specific cache types or full cache refresh.
Instructions
Clear the internal cache for stored data. Useful for debugging or when you know the data has changed. Supports granular cache clearing for both individual items and list caches.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cache_type | No | Type of cache to clear: "all" (default - clears all cache types), individual item caches ("cards", "dashboards", "tables", "databases", "collections", "fields"), list caches ("cards-list", "dashboards-list", "tables-list", "databases-list", "collections-list"), or bulk operations ("all-lists", "all-individual") | all |
Implementation Reference
- src/handlers/clearCache.ts:5-167 (handler)The core handler function implementing the clear_cache tool. Validates the cache_type parameter, clears the specified cache using MetabaseApiClient methods based on switch cases, logs the action, and returns a formatted JSON response with cache status information.export function handleClearCache( request: CallToolRequest, apiClient: MetabaseApiClient, logInfo: (message: string, data?: unknown) => void, logWarn: (message: string, data?: unknown, error?: Error) => void, logError: (message: string, error: unknown) => void ) { const requestId = 'clearCache'; // Generate a simple request ID for logging // Validate cache_type parameter with case insensitive handling const validCacheTypes = [ 'all', 'cards', 'dashboards', 'tables', 'databases', 'collections', 'fields', 'cards-list', 'dashboards-list', 'tables-list', 'databases-list', 'collections-list', 'all-lists', 'all-individual', ] as const; const cacheType = validateEnumValue( request.params?.arguments?.cache_type || 'all', validCacheTypes, 'cache_type', requestId, logWarn ); try { let message = ''; let cacheStatus = ''; switch (cacheType) { case 'cards': apiClient.clearCardsCache(); message = 'Cards cache cleared successfully (individual items only)'; cacheStatus = 'cards_cache_empty'; break; case 'dashboards': apiClient.clearDashboardsCache(); message = 'Dashboards cache cleared successfully (individual items only)'; cacheStatus = 'dashboards_cache_empty'; break; case 'tables': apiClient.clearTablesCache(); message = 'Tables cache cleared successfully (individual items only)'; cacheStatus = 'tables_cache_empty'; break; case 'databases': apiClient.clearDatabasesCache(); message = 'Databases cache cleared successfully (individual items only)'; cacheStatus = 'databases_cache_empty'; break; case 'collections': apiClient.clearCollectionsCache(); message = 'Collections cache cleared successfully (individual items only)'; cacheStatus = 'collections_cache_empty'; break; case 'fields': apiClient.clearFieldsCache(); message = 'Fields cache cleared successfully'; cacheStatus = 'fields_cache_empty'; break; case 'cards-list': apiClient.clearCardsListCache(); message = 'Cards list cache cleared successfully'; cacheStatus = 'cards_list_cache_empty'; break; case 'dashboards-list': apiClient.clearDashboardsListCache(); message = 'Dashboards list cache cleared successfully'; cacheStatus = 'dashboards_list_cache_empty'; break; case 'tables-list': apiClient.clearTablesListCache(); message = 'Tables list cache cleared successfully'; cacheStatus = 'tables_list_cache_empty'; break; case 'databases-list': apiClient.clearDatabasesListCache(); message = 'Databases list cache cleared successfully'; cacheStatus = 'databases_list_cache_empty'; break; case 'collections-list': apiClient.clearCollectionsListCache(); message = 'Collections list cache cleared successfully'; cacheStatus = 'collections_list_cache_empty'; break; case 'all-lists': apiClient.clearListCaches(); message = 'All list caches cleared successfully (cards, dashboards, tables, databases, collections)'; cacheStatus = 'all_list_caches_empty'; break; case 'all-individual': apiClient.clearCardsCache(); apiClient.clearDashboardsCache(); apiClient.clearTablesCache(); apiClient.clearDatabasesCache(); apiClient.clearCollectionsCache(); apiClient.clearFieldsCache(); message = 'All individual item caches cleared successfully (cards, dashboards, tables, databases, collections, fields)'; cacheStatus = 'all_individual_caches_empty'; break; case 'all': default: apiClient.clearAllCache(); message = 'All caches cleared successfully (individual items and lists for cards, dashboards, tables, databases, collections, and fields)'; cacheStatus = 'all_caches_empty'; break; } logInfo(message); return { content: [ { type: 'text', text: formatJson({ message, cache_type: cacheType, cache_status: cacheStatus, next_fetch_will_be: 'fresh from API', cache_info: { cache_explanation: 'Unified cache system with separate individual item and list caches for optimal performance', cache_types: { individual: 'Cache for specific items accessed by ID (cards, dashboards, tables, databases, collections, fields)', lists: 'Cache for bulk list operations (cards-list, dashboards-list, tables-list, databases-list, collections-list)', }, }, }), }, ], }; } catch (error: any) { throw handleApiError(error, { operation: 'Clear cache' }, logError); } }
- src/server.ts:442-469 (schema)JSON input schema for the clear_cache tool, defining the cache_type parameter with enum values matching the handler validation.inputSchema: { type: 'object', properties: { cache_type: { type: 'string', enum: [ 'all', 'cards', 'dashboards', 'tables', 'databases', 'collections', 'fields', 'cards-list', 'dashboards-list', 'tables-list', 'databases-list', 'collections-list', 'all-lists', 'all-individual', ], description: 'Type of cache to clear: "all" (default - clears all cache types), individual item caches ("cards", "dashboards", "tables", "databases", "collections", "fields"), list caches ("cards-list", "dashboards-list", "tables-list", "databases-list", "collections-list"), or bulk operations ("all-lists", "all-individual")', default: 'all', }, }, required: [], },
- src/server.ts:432-470 (registration)Registration of the clear_cache tool in the ListToolsRequestSchema handler, including name, description, annotations, and input schema.{ name: 'clear_cache', description: 'Clear the internal cache for stored data. Useful for debugging or when you know the data has changed. Supports granular cache clearing for both individual items and list caches.', annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, inputSchema: { type: 'object', properties: { cache_type: { type: 'string', enum: [ 'all', 'cards', 'dashboards', 'tables', 'databases', 'collections', 'fields', 'cards-list', 'dashboards-list', 'tables-list', 'databases-list', 'collections-list', 'all-lists', 'all-individual', ], description: 'Type of cache to clear: "all" (default - clears all cache types), individual item caches ("cards", "dashboards", "tables", "databases", "collections", "fields"), list caches ("cards-list", "dashboards-list", "tables-list", "databases-list", "collections-list"), or bulk operations ("all-lists", "all-individual")', default: 'all', }, }, required: [], }, },
- src/server.ts:556-565 (registration)Handler registration in the CallToolRequestSchema switch statement, mapping 'clear_cache' to the handleClearCache function.case 'clear_cache': return safeCall(() => handleClearCache( request, this.apiClient, this.logInfo.bind(this), this.logWarn.bind(this), this.logError.bind(this) ) );
- src/handlers/index.ts:5-5 (registration)Re-export of the handleClearCache function from the handlers index module, enabling easy import in server.ts.export { handleClearCache } from './clearCache.js';