Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewwormald committed Oct 11, 2024
1 parent 4e4c7cb commit 2a1d0b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions rsql/rcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ type rcache struct {
limit int
}

// enabled is the source of truth whether the rcache is enabled or not.
var enabled bool

func init() {
enabled = true
}
// cacheDisabled is the source of truth whether the rcache is disabled or not.
var cacheDisabled bool

// DisableCache results in all loading going straight through to the underlying loader.
func DisableCache() {
enabled = false
cacheDisabled = true
}

// newRCache returns a new read-through cache.
Expand Down Expand Up @@ -75,7 +71,7 @@ func (c *rcache) Load(ctx context.Context, dbc *sql.DB,
prev int64, lag time.Duration,
) ([]*reflex.Event, error) {
res, ok := c.maybeHit(prev+1, lag)
if enabled && ok {
if !cacheDisabled && ok {
rcacheHitsCounter.WithLabelValues(c.name).Inc()
return res, nil
}
Expand Down Expand Up @@ -126,7 +122,7 @@ func (c *rcache) readThrough(ctx context.Context, dbc *sql.DB,

// Recheck cache after waiting for lock
res, ok := c.maybeHitUnsafe(prev+1, lag)
if enabled && ok {
if !cacheDisabled && ok {
return res, nil
}

Expand Down
2 changes: 1 addition & 1 deletion rsql/rcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestRCache(t *testing.T) {
if test.disabled {
DisableCache()
t.Cleanup(func() {
enabled = true
cacheDisabled = false
})
}
q := newQ()
Expand Down

0 comments on commit 2a1d0b9

Please sign in to comment.