Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit b67c4a7

Browse files
authored
cody-gateway/actor: version actor source caches (#53263)
We've run into issues a few times now where the cache doesn't update fast enough on a breaking change. This adds a version prefix that allows us to invalidate caches on certain rollouts. Depends on https://github.com/sourcegraph/sourcegraph/pull/53265 being rolled out to all environments. ## Test plan Run locally with new prefix
1 parent 15d38ca commit b67c4a7

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

enterprise/cmd/cody-gateway/internal/actor/dotcomuser/dotcomuser.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import (
1818
"github.com/sourcegraph/sourcegraph/lib/errors"
1919
)
2020

21+
// SourceVersion should be bumped whenever the format of any cached data in this
22+
// actor source implementation is changed. This effectively expires all entries.
23+
const SourceVersion = "v1"
24+
2125
// dotcom user gateway tokens are always a prefix of 4 characters (sgd_)
2226
// followed by a 64-character hex-encoded SHA256 hash
2327
const tokenLength = 4 + 64

enterprise/cmd/cody-gateway/internal/actor/productsubscription/productsubscription.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import (
2323
"github.com/sourcegraph/sourcegraph/lib/errors"
2424
)
2525

26+
// SourceVersion should be bumped whenever the format of any cached data in this
27+
// actor source implementation is changed. This effectively expires all entries.
28+
const SourceVersion = "v1"
29+
2630
// product subscription tokens are always a prefix of 4 characters (sgs_ or slk_)
2731
// followed by a 64-character hex-encoded SHA256 hash
2832
const tokenLength = 4 + 64

enterprise/cmd/cody-gateway/shared/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package shared
22

33
import (
44
"context"
5+
"fmt"
56
"net/http"
67
"net/url"
78
"os"
@@ -77,13 +78,13 @@ func Main(ctx context.Context, obctx *observation.Context, ready service.ReadyFu
7778
anonymous.NewSource(config.AllowAnonymous, config.ActorConcurrencyLimit),
7879
productsubscription.NewSource(
7980
obctx.Logger,
80-
rcache.NewWithTTL("product-subscriptions", int(config.SourcesCacheTTL.Seconds())),
81+
rcache.NewWithTTL(fmt.Sprintf("product-subscriptions:%s", productsubscription.SourceVersion), int(config.SourcesCacheTTL.Seconds())),
8182
dotcomClient,
8283
config.Dotcom.InternalMode,
8384
config.ActorConcurrencyLimit,
8485
),
8586
dotcomuser.NewSource(obctx.Logger,
86-
rcache.NewWithTTL("dotcom-users", int(config.SourcesCacheTTL.Seconds())),
87+
rcache.NewWithTTL(fmt.Sprintf("dotcom-users:%s", dotcomuser.SourceVersion), int(config.SourcesCacheTTL.Seconds())),
8788
dotcomClient,
8889
config.ActorConcurrencyLimit,
8990
),

0 commit comments

Comments
 (0)