Madan Jampani

CachingAsyncConsistentMap: evict failed get responses from cache

AtomixLeaderElector: evict failed getLeadership responses from cache immediately

Change-Id: I084abbe8f4669b98f85bc60dc6af9240630b7ce0
(cherry picked from commit 77012446)
...@@ -95,7 +95,12 @@ public class CachingAsyncConsistentMap<K, V> extends DelegatingAsyncConsistentMa ...@@ -95,7 +95,12 @@ public class CachingAsyncConsistentMap<K, V> extends DelegatingAsyncConsistentMa
95 95
96 @Override 96 @Override
97 public CompletableFuture<Versioned<V>> get(K key) { 97 public CompletableFuture<Versioned<V>> get(K key) {
98 - return cache.getUnchecked(key); 98 + return cache.getUnchecked(key)
99 + .whenComplete((r, e) -> {
100 + if (e != null) {
101 + cache.invalidate(key);
102 + }
103 + });
99 } 104 }
100 105
101 @Override 106 @Override
......
...@@ -135,7 +135,12 @@ public class AtomixLeaderElector extends AbstractResource<AtomixLeaderElector> ...@@ -135,7 +135,12 @@ public class AtomixLeaderElector extends AbstractResource<AtomixLeaderElector>
135 135
136 @Override 136 @Override
137 public CompletableFuture<Leadership> getLeadership(String topic) { 137 public CompletableFuture<Leadership> getLeadership(String topic) {
138 - return cache.getUnchecked(topic); 138 + return cache.getUnchecked(topic)
139 + .whenComplete((r, e) -> {
140 + if (e != null) {
141 + cache.invalidate(topic);
142 + }
143 + });
139 } 144 }
140 145
141 @Override 146 @Override
......