@@ -411,7 +411,7 @@ protected static Map<String, Object> retrieveResponseDetails(IHttpService servic
411411 private static Map <String , Object > retrieveResponseDetails (IHttpService service , byte [] request , int retryCount ) {
412412 try {
413413 String hostKey = service .getHost ();
414- String cacheKey = service . toString () + Arrays . hashCode ( request );
414+ String cacheKey = buildServiceCacheKey ( service , request );
415415
416416 // Check circuit breaker
417417 if (isCircuitOpen (hostKey )) {
@@ -478,6 +478,28 @@ private static Map<String, Object> retrieveResponseDetails(IHttpService service,
478478 return null ;
479479 }
480480 }
481+
482+ /**
483+ * Builds a cache key that normalizes the service attributes (protocol, host, port)
484+ * and appends the request hash. This ensures equivalent services share cache
485+ * entries while keeping cache growth in check.
486+ */
487+ private static String buildServiceCacheKey (IHttpService service , byte [] request ) {
488+ String protocol = service .getProtocol () != null
489+ ? service .getProtocol ().toLowerCase (Locale .ROOT )
490+ : "http" ;
491+ String host = service .getHost () != null
492+ ? service .getHost ().toLowerCase (Locale .ROOT )
493+ : "" ;
494+ int port = service .getPort ();
495+
496+ if (port <= 0 ) {
497+ port = "https" .equals (protocol ) ? 443 : 80 ;
498+ }
499+
500+ String serviceKey = protocol + "://" + host + ":" + port ;
501+ return serviceKey + "|" + Arrays .hashCode (request );
502+ }
481503
482504 private static boolean isCircuitOpen (String hostKey ) {
483505 AtomicInteger failures = FAILURE_COUNTS .computeIfAbsent (hostKey , k -> new AtomicInteger (0 ));
0 commit comments