Open
Description
Problem
The QuerySyncStats
method in tapdb/universe_stats.go:930-936
currently purges the entire sync stats cache after the cache duration expires. This leads to cold cache hits for subsequent requests, which can take a significant time to load.
Current Behavior
When the cache duration expires, the code simply wipes the entire cache:
u.syncStatsRefresh = time.AfterFunc(u.opts.cacheDuration, func() {
log.Infof("Purging sync stats cache, duration=%v",
u.opts.cacheDuration)
u.syncStatsCache.wipe()
})
Expected Behavior
Instead of purging the cache entirely, the system should:
- Load fresh data in the background
- Continue serving the existing cached data while the refresh is happening
- Atomically swap to the new data once the background refresh is complete
This would prevent cold cache hits and improve response times for users.
Impact
Users experience slow response times after cache expiration, as the entire dataset needs to be reloaded from scratch on the next request.