fix: address review feedback on cache invalidation
- Fix cache not repopulated after invalidation: Always update cache with fresh data instead of just deleting on mismatch - Fix race condition: Hold mutex lock during entire fetch operation to prevent SaveEvent from running between fetch and cache update - Improve test: Add second GetLatestVersion call to verify cache was properly repopulated after invalidation Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -1390,6 +1390,15 @@ func TestJetStreamEventStore_CacheInvalidationOnExternalWrite(t *testing.T) {
|
||||
t.Errorf("store1 should see version 2 after external write, got %d", v2)
|
||||
}
|
||||
|
||||
// Verify cache was repopulated - second GetLatestVersion should use cache efficiently
|
||||
v2Again, err := store1.GetLatestVersion(actorID)
|
||||
if err != nil {
|
||||
t.Fatalf("Second GetLatestVersion from store1 failed: %v", err)
|
||||
}
|
||||
if v2Again != 2 {
|
||||
t.Errorf("store1 cache should have version 2, got %d", v2Again)
|
||||
}
|
||||
|
||||
// store2: Save event v3 (another external write)
|
||||
event3 := &aether.Event{
|
||||
ID: "evt-3",
|
||||
|
||||
Reference in New Issue
Block a user