Skip to content

Commit eca7189

Browse files
committed
fix: prevent cache inconsistency for aggregates receiving events from other clients
1 parent d3c8145 commit eca7189

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

java-client/src/main/java/io/fluxcapacitor/javaclient/persisting/repository/CachingAggregateRepository.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,14 @@ private void handleEvent(DeserializingMessage m) {
161161
cache.<Entity<?>>computeIfPresent(
162162
id, (i, before) -> {
163163
Long lastIndex = before.highestEventIndex();
164-
if (lastIndex == null || lastIndex < index) {
164+
if (lastIndex == null) {
165+
//The cached aggregate was last updated by this client, but we received an event
166+
// from another client. If we would apply the event, the version ordering of this
167+
// aggregate would not be consistent with the global event index order. To prevent
168+
// this, we delete this aggregate from the cache.
169+
return null;
170+
}
171+
if (lastIndex < index) {
165172
boolean wasLoading = Entity.isLoading();
166173
try {
167174
Entity.loading.set(true);

0 commit comments

Comments
 (0)