@@ -841,7 +841,7 @@ public JedisClusterTopologyProvider(JedisCluster cluster, Duration cacheTimeout)
841
841
public ClusterTopology getTopology () {
842
842
843
843
JedisClusterTopology topology = cached ;
844
- if (shouldUseCachedValue (topology )) {
844
+ if (shouldUseCachedValue ()) { // retain method call behaviour
845
845
return topology ;
846
846
}
847
847
@@ -854,9 +854,8 @@ public ClusterTopology getTopology() {
854
854
855
855
try (Connection connection = entry .getValue ().getResource ()) {
856
856
857
-
858
857
Set <RedisClusterNode > nodes = Converters .toSetOfRedisClusterNodes (new Jedis (connection ).clusterNodes ());
859
- topology = cached = new JedisClusterTopology (nodes , System .currentTimeMillis ());
858
+ topology = cached = new JedisClusterTopology (nodes , System .currentTimeMillis (), cacheTimeMs );
860
859
return topology ;
861
860
862
861
} catch (Exception ex ) {
@@ -884,9 +883,9 @@ public ClusterTopology getTopology() {
884
883
* @since 2.2
885
884
* @deprecated since 3.3.4, use {@link #shouldUseCachedValue(JedisClusterTopology)} instead.
886
885
*/
887
- @ Deprecated (since = "3.3.4" )
886
+ @ Deprecated (since = "3.3.4" , forRemoval = true )
888
887
protected boolean shouldUseCachedValue () {
889
- return false ;
888
+ return shouldUseCachedValue ( cached ) ;
890
889
}
891
890
892
891
/**
@@ -899,22 +898,38 @@ protected boolean shouldUseCachedValue() {
899
898
* @since 3.3.4
900
899
*/
901
900
protected boolean shouldUseCachedValue (@ Nullable JedisClusterTopology topology ) {
902
- return topology != null && topology .getTime () + cacheTimeMs > System .currentTimeMillis ();
901
+ return topology != null && topology .getMaxTime () > System .currentTimeMillis ();
903
902
}
904
903
}
905
904
906
905
protected static class JedisClusterTopology extends ClusterTopology {
907
906
908
907
private final long time ;
908
+ private final long timeoutMs ;
909
909
910
- public JedisClusterTopology (Set <RedisClusterNode > nodes , long time ) {
910
+ JedisClusterTopology (Set <RedisClusterNode > nodes , long creationTimeMs , long timeoutMs ) {
911
911
super (nodes );
912
- this .time = time ;
912
+ this .time = creationTimeMs ;
913
+ this .timeoutMs = timeoutMs ;
913
914
}
914
915
916
+ /**
917
+ * Get the time in ms when the {@link ClusterTopology} was captured.
918
+ *
919
+ * @return ClusterTopology time.
920
+ */
915
921
public long getTime () {
916
922
return time ;
917
923
}
924
+
925
+ /**
926
+ * Get the maximum time in ms the {@link ClusterTopology} should be used before a refresh is required.
927
+ *
928
+ * @return ClusterTopology maximum age.
929
+ */
930
+ long getMaxTime () {
931
+ return time + timeoutMs ;
932
+ }
918
933
}
919
934
920
935
protected JedisCluster getCluster () {
0 commit comments