diff --git a/splitio/proxy/caching/workers.go b/splitio/proxy/caching/workers.go index b3d16827..52dc03ab 100644 --- a/splitio/proxy/caching/workers.go +++ b/splitio/proxy/caching/workers.go @@ -99,6 +99,7 @@ func (c *CacheAwareSegmentSynchronizer) SynchronizeSegment(name string, till *in result, err := c.wrapped.SynchronizeSegment(name, till) if current := result.NewChangeNumber; current > previous || (previous != -1 && current == -1) { c.cacheFlusher.EvictBySurrogate(MakeSurrogateForSegmentChanges(name)) + c.cacheFlusher.EvictBySurrogate(LargeSegmentSurrogate) } // remove individual entries for each affected key @@ -130,6 +131,7 @@ func (c *CacheAwareSegmentSynchronizer) SynchronizeSegments() (map[string]segmen if pcn, _ := previousCNs[segmentName]; ccn > pcn || (pcn > 0 && ccn == -1) { // if the segment was updated or the segment was removed, evict it c.cacheFlusher.EvictBySurrogate(MakeSurrogateForSegmentChanges(segmentName)) + c.cacheFlusher.EvictBySurrogate(LargeSegmentSurrogate) } for idx := range result.UpdatedKeys { @@ -182,7 +184,7 @@ func (c *CacheAwareLargeSegmentSynchronizer) SynchronizeLargeSegment(name string previous := c.largeSegmentStorage.ChangeNumber(name) newCN, err := c.wrapped.SynchronizeLargeSegment(name, till) - c.shouldEvictBySurrogate(previous, *newCN) + c.evictByLargeSegmentSurrogate(previous, *newCN) return newCN, err } @@ -199,7 +201,7 @@ func (c *CacheAwareLargeSegmentSynchronizer) SynchronizeLargeSegments() (map[str results, err := c.wrapped.SynchronizeLargeSegments() for name, currentCN := range results { - c.shouldEvictBySurrogate(previousCNs[name], *currentCN) + c.evictByLargeSegmentSurrogate(previousCNs[name], *currentCN) } return results, err @@ -213,12 +215,12 @@ func (c *CacheAwareLargeSegmentSynchronizer) SynchronizeLargeSegmentUpdate(lsRFD previous := c.largeSegmentStorage.ChangeNumber(lsRFDResponseDTO.Name) newCN, err := c.wrapped.SynchronizeLargeSegmentUpdate(lsRFDResponseDTO) - c.shouldEvictBySurrogate(previous, *newCN) + c.evictByLargeSegmentSurrogate(previous, *newCN) return newCN, err } -func (c *CacheAwareLargeSegmentSynchronizer) shouldEvictBySurrogate(previousCN int64, currentCN int64) { +func (c *CacheAwareLargeSegmentSynchronizer) evictByLargeSegmentSurrogate(previousCN int64, currentCN int64) { if currentCN > previousCN || currentCN == -1 { c.cacheFlusher.EvictBySurrogate(LargeSegmentSurrogate) } diff --git a/splitio/proxy/caching/workers_test.go b/splitio/proxy/caching/workers_test.go index 2c83d49a..4eaf70fe 100644 --- a/splitio/proxy/caching/workers_test.go +++ b/splitio/proxy/caching/workers_test.go @@ -144,6 +144,7 @@ func TestCacheAwareSegmentSyncSingle(t *testing.T) { cacheFlusher.On("EvictBySurrogate", MakeSurrogateForSegmentChanges("segment1")).Times(2) cacheFlusher.On("Evict", "/api/mySegments/k1").Times(2) cacheFlusher.On("Evict", "gzip::/api/mySegments/k1").Times(2) + cacheFlusher.On("EvictBySurrogate", LargeSegmentSurrogate).Times(2) var segmentStorage mocks.SegmentStorageMock segmentStorage.On("ChangeNumber", "segment1").Return(int64(0), nil).Once() @@ -189,6 +190,7 @@ func TestCacheAwareSegmentSyncAllSegments(t *testing.T) { cacheFlusher.On("EvictBySurrogate", MakeSurrogateForSegmentChanges("segment2")).Times(1) cacheFlusher.On("Evict", "/api/mySegments/k1").Times(3) cacheFlusher.On("Evict", "gzip::/api/mySegments/k1").Times(3) + cacheFlusher.On("EvictBySurrogate", LargeSegmentSurrogate).Times(3) var segmentStorage mocks.SegmentStorageMock segmentStorage.On("ChangeNumber", "segment2").Return(int64(0), nil).Once()