fix: address review feedback on cache invalidation
Some checks failed
CI / build (pull_request) Successful in 19s
CI / integration (pull_request) Failing after 2m0s

- 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:
Claude Code
2026-01-13 01:31:03 +01:00
parent 6de897ef60
commit fd1938672e
2 changed files with 21 additions and 14 deletions

View File

@@ -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",