diff --git a/mod/node-api/backend/cache/cache.go b/mod/node-api/backend/cache/cache.go index 59208f8f80..11c61ca256 100644 --- a/mod/node-api/backend/cache/cache.go +++ b/mod/node-api/backend/cache/cache.go @@ -57,6 +57,8 @@ func (c *QueryCache) GetQueryContext(slot math.Slot) (context.Context, bool) { } // AddQueryContext adds a query context to the cache for the given slot. +// +//nolint:revive // ctx is the value in cache. func (c *QueryCache) AddQueryContext(slot math.Slot, ctx context.Context) { c.queryCtxCache.Add(slot, ctx) } diff --git a/mod/node-api/backend/cache/cache_test.go b/mod/node-api/backend/cache/cache_test.go index 54c464428c..512a5e1ca1 100644 --- a/mod/node-api/backend/cache/cache_test.go +++ b/mod/node-api/backend/cache/cache_test.go @@ -37,12 +37,13 @@ func TestQueryCache(t *testing.T) { } cacheUnderTest := cache.NewQueryCache(cacheConfig) - ctx := context.WithValue(context.Background(), "test", "test") + //nolint:revive,staticcheck // ok for test. + ctx := context.WithValue(context.Background(), "testK", "testV") t.Run("Get from empty cache", func(t *testing.T) { - ctx, ok := cacheUnderTest.GetQueryContext(0) + emtpyCtx, ok := cacheUnderTest.GetQueryContext(0) require.False(t, ok) - require.Nil(t, ctx) + require.Nil(t, emtpyCtx) }) t.Run("Set and Get", func(t *testing.T) { @@ -51,7 +52,7 @@ func TestQueryCache(t *testing.T) { ctx2, ok := cacheUnderTest.GetQueryContext(slot) require.True(t, ok) - require.Equal(t, ctx.Value("test"), ctx2.Value("test")) + require.Equal(t, ctx.Value("testK"), ctx2.Value("testK")) }) t.Run("Overwrite existing", func(t *testing.T) { @@ -60,14 +61,15 @@ func TestQueryCache(t *testing.T) { ctx2, ok := cacheUnderTest.GetQueryContext(slot) require.True(t, ok) - require.Equal(t, ctx.Value("test"), ctx2.Value("test")) + require.Equal(t, ctx.Value("testK"), ctx2.Value("testK")) - newCtx := context.WithValue(context.Background(), "test", "new_test") + //nolint:revive,staticcheck // ok for test. + newCtx := context.WithValue(context.Background(), "testK", "testV_new") cacheUnderTest.AddQueryContext(slot, newCtx) ctx3, ok := cacheUnderTest.GetQueryContext(slot) require.True(t, ok) - require.Equal(t, newCtx.Value("test"), ctx3.Value("test")) + require.Equal(t, newCtx.Value("testK"), ctx3.Value("testK")) }) t.Run("Prune and verify deletion", func(t *testing.T) { diff --git a/mod/node-api/backend/cache/config.go b/mod/node-api/backend/cache/config.go index 2271a0c0c1..999460ada4 100644 --- a/mod/node-api/backend/cache/config.go +++ b/mod/node-api/backend/cache/config.go @@ -23,8 +23,11 @@ package cache import "time" const ( + // defaultQueryContextSize is the default size of the query context cache. defaultQueryContextSize = 20 - defaultQueryContextTTL = 0 + // defaultQueryContextTTL is 0, which means the query context does not have + // an expiry. + defaultQueryContextTTL = 0 ) // Config is the configuration for an EngineCache.