clear_cache
Clear cache in SAP Commerce Cloud (Hybris) to resolve data display issues by removing outdated cached content, with optional targeting of specific cache types.
Instructions
Clear the Hybris cache
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cacheType | No | Specific cache type to clear (optional, clears all if not specified) |
Implementation Reference
- src/hybris-client.ts:675-709 (handler)Primary handler implementation for clearing Hybris cache using a Groovy script that invokes cacheController.clearCache() or general cache clear.async clearCache(cacheType?: string): Promise<{ success: boolean; message: string }> { // Use Groovy script to clear cache const escapedType = cacheType ? this.escapeGroovyString(cacheType) : ''; const script = ` import de.hybris.platform.core.Registry def cacheType = "${escapedType}" if (cacheType == "all" || cacheType == "") { Registry.getCurrentTenant().getCache().clear() println "All caches cleared" return "SUCCESS" } else { // Clear specific cache region if supported try { def cacheController = spring.getBean("cacheController") cacheController.clearCache() println "Cache cleared: " + cacheType return "SUCCESS" } catch (Exception e) { Registry.getCurrentTenant().getCache().clear() println "Cleared all caches (specific cache type not supported)" return "SUCCESS" } } `; const result = await this.executeGroovyScript(script); const output = result.output || ''; const execResult = String(result.result || ''); const success = output.includes('cleared') || execResult === 'SUCCESS'; return { success, message: success ? 'Cache cleared successfully' : `Failed to clear cache: ${output || execResult || 'Unknown error'}`, }; }
- src/index.ts:444-448 (handler)MCP tool call handler dispatch for 'clear_cache', validates input and calls hybrisClient.clearCache()case 'clear_cache': result = await hybrisClient.clearCache( validateString(args, 'cacheType', false) ); break;
- src/index.ts:280-292 (schema)Tool definition including name, description, and input schema for 'clear_cache' used for registration and validation{ name: 'clear_cache', description: 'Clear the Hybris cache', inputSchema: { type: 'object', properties: { cacheType: { type: 'string', description: 'Specific cache type to clear (optional, clears all if not specified)', }, }, }, },
- src/index.ts:359-361 (registration)Registration of the tools list handler, which exposes the clear_cache tool via ListToolsRequestserver.setRequestHandler(ListToolsRequestSchema, async () => { return { tools }; });
- src/hybris-client.ts:690-691 (helper)Direct call to Hybris cacheController.clearCache() within the Groovy script for specific cache clearing.def cacheController = spring.getBean("cacheController") cacheController.clearCache()