diff --git a/go.mod b/go.mod index 55530ba1..7d7e7746 100644 --- a/go.mod +++ b/go.mod @@ -8,15 +8,13 @@ require ( github.com/gin-gonic/gin v1.10.0 github.com/google/uuid v1.3.0 github.com/splitio/gincache v1.0.1 - github.com/splitio/go-split-commons/v6 v6.0.2-0.20241125153044-959311072c68 + github.com/splitio/go-split-commons/v6 v6.0.2-0.20241126190617-03ffbb3a100f github.com/splitio/go-toolkit/v5 v5.4.0 github.com/stretchr/testify v1.9.0 go.etcd.io/bbolt v1.3.6 golang.org/x/exp v0.0.0-20231006140011-7918f672742d ) -replace github.com/splitio/go-split-commons/v6 => /Users/maurosanz/go/src/github/splitio/go-split-commons - require ( github.com/bits-and-blooms/bitset v1.3.1 // indirect github.com/bits-and-blooms/bloom/v3 v3.3.1 // indirect diff --git a/go.sum b/go.sum index c6504405..d7333a81 100644 --- a/go.sum +++ b/go.sum @@ -93,6 +93,8 @@ github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUA github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/splitio/gincache v1.0.1 h1:dLYdANY/BqH4KcUMCe/LluLyV5WtuE/LEdQWRE06IXU= github.com/splitio/gincache v1.0.1/go.mod h1:CcgJDSM9Af75kyBH0724v55URVwMBuSj5x1eCWIOECY= +github.com/splitio/go-split-commons/v6 v6.0.2-0.20241126190617-03ffbb3a100f h1:FbR7KHn2kdtBda7CZVxut2qfFH7ZI4XW+FV6B0JpWgM= +github.com/splitio/go-split-commons/v6 v6.0.2-0.20241126190617-03ffbb3a100f/go.mod h1:D/XIY/9Hmfk9ivWsRsJVp439kEdmHbzUi3PKzQQDOXY= github.com/splitio/go-toolkit/v5 v5.4.0 h1:g5WFpRhQomnXCmvfsNOWV4s5AuUrWIZ+amM68G8NBKM= github.com/splitio/go-toolkit/v5 v5.4.0/go.mod h1:xYhUvV1gga9/1029Wbp5pjnR6Cy8nvBpjw99wAbsMko= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/splitio/proxy/caching/caching.go b/splitio/proxy/caching/caching.go index cc64e021..665731af 100644 --- a/splitio/proxy/caching/caching.go +++ b/splitio/proxy/caching/caching.go @@ -19,21 +19,17 @@ const ( // SplitSurrogate key (we only need one, since all splitChanges should be expired when an update is processed) SplitSurrogate = "sp" + // LargeSegmentSurrogate key (we only need one, since all memberships should be expired when an update is processed) + LargeSegmentSurrogate = "ls" + // AuthSurrogate key (having push disabled, it's safe to cache this and return it on all requests) AuthSurrogate = "au" segmentPrefix = "se::" - - largeSegmentPrefix = "ls::" ) const cacheSize = 1000000 -// MakeSurrogateForSegmentChanges creates a surrogate key for the segment being queried -func MakeSurrogateForLargeSegmentChanges(name string) string { - return largeSegmentPrefix + name -} - // MakeSurrogateForSegmentChanges creates a surrogate key for the segment being queried func MakeSurrogateForSegmentChanges(segmentName string) string { return segmentPrefix + segmentName @@ -45,14 +41,6 @@ func MakeSurrogateForMySegments(mysegments []dtos.MySegmentDTO) []string { return nil } -// MakeMembershipsEntries create a cache entry key for Memberships -func MakeMembershipsEntries(key string) []string { - return []string{ - "/api/memberships/" + key, - "gzip::/api/memberships/" + key, - } -} - // MakeMySegmentsEntry create a cache entry key for mysegments func MakeMySegmentsEntries(key string) []string { return []string{ diff --git a/splitio/proxy/caching/workers.go b/splitio/proxy/caching/workers.go index 682dc466..b3d16827 100644 --- a/splitio/proxy/caching/workers.go +++ b/splitio/proxy/caching/workers.go @@ -182,7 +182,7 @@ func (c *CacheAwareLargeSegmentSynchronizer) SynchronizeLargeSegment(name string previous := c.largeSegmentStorage.ChangeNumber(name) newCN, err := c.wrapped.SynchronizeLargeSegment(name, till) - c.shouldEvictBySurrogate(name, previous, *newCN) + c.shouldEvictBySurrogate(previous, *newCN) return newCN, err } @@ -198,19 +198,13 @@ func (c *CacheAwareLargeSegmentSynchronizer) SynchronizeLargeSegments() (map[str } results, err := c.wrapped.SynchronizeLargeSegments() - for name, res := range results { - c.shouldEvictBySurrogate(name, previousCNs[name], *res) + for name, currentCN := range results { + c.shouldEvictBySurrogate(previousCNs[name], *currentCN) } return results, err } -func (c *CacheAwareLargeSegmentSynchronizer) shouldEvictBySurrogate(name string, previousCN int64, currentCN int64) { - if currentCN > previousCN || (previousCN != -1 && currentCN == -1) { - c.cacheFlusher.EvictBySurrogate(MakeSurrogateForLargeSegmentChanges(name)) - } -} - func (c *CacheAwareLargeSegmentSynchronizer) IsCached(name string) bool { return c.wrapped.IsCached(name) } @@ -219,7 +213,13 @@ func (c *CacheAwareLargeSegmentSynchronizer) SynchronizeLargeSegmentUpdate(lsRFD previous := c.largeSegmentStorage.ChangeNumber(lsRFDResponseDTO.Name) newCN, err := c.wrapped.SynchronizeLargeSegmentUpdate(lsRFDResponseDTO) - c.shouldEvictBySurrogate(lsRFDResponseDTO.Name, previous, *newCN) + c.shouldEvictBySurrogate(previous, *newCN) return newCN, err } + +func (c *CacheAwareLargeSegmentSynchronizer) shouldEvictBySurrogate(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 8f50c625..2c83d49a 100644 --- a/splitio/proxy/caching/workers_test.go +++ b/splitio/proxy/caching/workers_test.go @@ -240,7 +240,7 @@ func TestSynchronizeLargeSegment(t *testing.T) { var splitStorage mocks.SplitStorageMock var cacheFlusher mocks.CacheFlusherMock - cacheFlusher.On("EvictBySurrogate", MakeSurrogateForLargeSegmentChanges(lsName)).Once() + cacheFlusher.On("EvictBySurrogate", LargeSegmentSurrogate).Once() var largeSegmentStorage mocks.LargeSegmentStorageMock largeSegmentStorage.On("ChangeNumber", lsName).Return(int64(-1)).Once() @@ -310,8 +310,7 @@ func TestSynchronizeLargeSegments(t *testing.T) { splitStorage.On("LargeSegmentNames").Return(set.NewSet("ls1", "ls2")) var cacheFlusher mocks.CacheFlusherMock - cacheFlusher.On("EvictBySurrogate", MakeSurrogateForLargeSegmentChanges("ls1")).Once() - cacheFlusher.On("EvictBySurrogate", MakeSurrogateForLargeSegmentChanges("ls2")).Once() + cacheFlusher.On("EvictBySurrogate", LargeSegmentSurrogate).Times(2) var cn1 int64 = 100 var cn2 int64 = 200