Madan Jampani
Committed by Gerrit Code Review

CachingAsyncConsistentMap: evict failed get responses from cache

AtomixLeaderElector: evict failed getLeadership responses from cache immediately

Change-Id: I084abbe8f4669b98f85bc60dc6af9240630b7ce0
...@@ -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
...@@ -133,11 +138,11 @@ public class CachingAsyncConsistentMap<K, V> extends DelegatingAsyncConsistentMa ...@@ -133,11 +138,11 @@ public class CachingAsyncConsistentMap<K, V> extends DelegatingAsyncConsistentMa
133 @Override 138 @Override
134 public CompletableFuture<Boolean> remove(K key, V value) { 139 public CompletableFuture<Boolean> remove(K key, V value) {
135 return super.remove(key, value) 140 return super.remove(key, value)
136 - .whenComplete((r, e) -> { 141 + .whenComplete((r, e) -> {
137 - if (r) { 142 + if (r) {
138 - cache.invalidate(key); 143 + cache.invalidate(key);
139 - } 144 + }
140 - }); 145 + });
141 } 146 }
142 147
143 @Override 148 @Override
...@@ -153,7 +158,7 @@ public class CachingAsyncConsistentMap<K, V> extends DelegatingAsyncConsistentMa ...@@ -153,7 +158,7 @@ public class CachingAsyncConsistentMap<K, V> extends DelegatingAsyncConsistentMa
153 @Override 158 @Override
154 public CompletableFuture<Versioned<V>> replace(K key, V value) { 159 public CompletableFuture<Versioned<V>> replace(K key, V value) {
155 return super.replace(key, value) 160 return super.replace(key, value)
156 - .whenComplete((r, e) -> cache.invalidate(key)); 161 + .whenComplete((r, e) -> cache.invalidate(key));
157 } 162 }
158 163
159 @Override 164 @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
......