Skip to content

tapdb: QuerySyncStats purges cache instead of refreshing in background #1631

Open
@Roasbeef

Description

@Roasbeef

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:

  1. Load fresh data in the background
  2. Continue serving the existing cached data while the refresh is happening
  3. 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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions