Skip to content

Commit 366c5f5

Browse files
Add caching to all user-enabled configs other than healthcheck lb. (#1208)
1 parent 6677d16 commit 366c5f5

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/annotation/LoadBalancerClientConfiguration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -120,7 +120,7 @@ public ServiceInstanceListSupplier healthCheckDiscoveryClientServiceInstanceList
120120
public ServiceInstanceListSupplier requestBasedStickySessionDiscoveryClientServiceInstanceListSupplier(
121121
ConfigurableApplicationContext context) {
122122
return ServiceInstanceListSupplier.builder().withDiscoveryClient().withRequestBasedStickySession()
123-
.build(context);
123+
.withCaching().build(context);
124124
}
125125

126126
@Bean
@@ -130,7 +130,7 @@ public ServiceInstanceListSupplier requestBasedStickySessionDiscoveryClientServi
130130
public ServiceInstanceListSupplier sameInstancePreferenceServiceInstanceListSupplier(
131131
ConfigurableApplicationContext context) {
132132
return ServiceInstanceListSupplier.builder().withDiscoveryClient().withSameInstancePreference()
133-
.build(context);
133+
.withCaching().build(context);
134134
}
135135

136136
}
@@ -176,7 +176,7 @@ public ServiceInstanceListSupplier healthCheckDiscoveryClientServiceInstanceList
176176
public ServiceInstanceListSupplier requestBasedStickySessionDiscoveryClientServiceInstanceListSupplier(
177177
ConfigurableApplicationContext context) {
178178
return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient().withRequestBasedStickySession()
179-
.build(context);
179+
.withCaching().build(context);
180180
}
181181

182182
@Bean
@@ -186,7 +186,7 @@ public ServiceInstanceListSupplier requestBasedStickySessionDiscoveryClientServi
186186
public ServiceInstanceListSupplier sameInstancePreferenceServiceInstanceListSupplier(
187187
ConfigurableApplicationContext context) {
188188
return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient().withSameInstancePreference()
189-
.build(context);
189+
.withCaching().build(context);
190190
}
191191

192192
}

spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/annotation/LoadBalancerClientConfigurationTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -119,10 +119,13 @@ void shouldInstantiateRequestBasedStickySessionServiceInstanceListSupplierTests(
119119
.withPropertyValues("spring.cloud.loadbalancer.configurations=request-based-sticky-session")
120120
.run(context -> {
121121
ServiceInstanceListSupplier supplier = context.getBean(ServiceInstanceListSupplier.class);
122-
then(supplier).isInstanceOf(RequestBasedStickySessionServiceInstanceListSupplier.class);
122+
then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class);
123123
ServiceInstanceListSupplier delegate = ((DelegatingServiceInstanceListSupplier) supplier)
124124
.getDelegate();
125-
then(delegate).isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
125+
then(delegate).isInstanceOf(RequestBasedStickySessionServiceInstanceListSupplier.class);
126+
ServiceInstanceListSupplier secondDelegate = ((DelegatingServiceInstanceListSupplier) delegate)
127+
.getDelegate();
128+
then(secondDelegate).isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class);
126129
});
127130
}
128131

0 commit comments

Comments
 (0)