@@ -854,9 +854,8 @@ public ClusterTopology getTopology() {
854854
855855 try (Connection connection = entry.getValue().getResource()) {
856856
857-
858857 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 );
860859 return topology;
861860
862861 } catch (Exception ex) {
@@ -884,9 +883,9 @@ public ClusterTopology getTopology() {
884883 * @since 2.2
885884 * @deprecated since 3.3.4, use {@link #shouldUseCachedValue(JedisClusterTopology)} instead.
886885 */
887- @Deprecated(since = "3.3.4")
886+ @Deprecated(since = "3.3.4", forRemoval = true )
888887 protected boolean shouldUseCachedValue() {
889- return false ;
888+ return shouldUseCachedValue(cached) ;
890889 }
891890
892891 /**
@@ -899,22 +898,38 @@ protected boolean shouldUseCachedValue() {
899898 * @since 3.3.4
900899 */
901900 protected boolean shouldUseCachedValue(@Nullable JedisClusterTopology topology) {
902- return topology != null && topology.getTime() + cacheTimeMs > System.currentTimeMillis();
901+ return topology != null && topology.getMaxTime() > System.currentTimeMillis();
903902 }
904903 }
905904
906905 protected static class JedisClusterTopology extends ClusterTopology {
907906
908907 private final long time;
908+ private final long timeoutMs;
909909
910- public JedisClusterTopology(Set<RedisClusterNode> nodes, long time ) {
910+ JedisClusterTopology(Set<RedisClusterNode> nodes, long creationTimeMs, long timeoutMs ) {
911911 super(nodes);
912- this.time = time;
912+ this.time = creationTimeMs;
913+ this.timeoutMs = timeoutMs;
913914 }
914915
916+ /**
917+ * Get the time in ms when the {@link ClusterTopology} was captured.
918+ *
919+ * @return ClusterTopology time.
920+ */
915921 public long getTime() {
916922 return time;
917923 }
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+ }
918933 }
919934
920935 protected JedisCluster getCluster() {
0 commit comments