feat: cache topic and subscription reads
This commit is contained in:
@@ -409,3 +409,28 @@ func TestInvalidateGroupSettingsUsesTopicCacheKey(t *testing.T) {
|
||||
t.Fatalf("unexpected deleted objects: %#v", runtime.deletedObjects)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTopicAndSubscriptionCacheTTLIsShort(t *testing.T) {
|
||||
runtime := &redisGroupMessageRuntime{cfg: redisConfig{CacheTTL: 300, ShortTTL: 600}}
|
||||
for _, namespace := range []string{cacheNamespaceTopic, cacheNamespaceSub} {
|
||||
if got := runtime.cacheTTL(namespace); got != time.Minute {
|
||||
t.Fatalf("cache TTL for %s = %v, want 1m", namespace, got)
|
||||
}
|
||||
}
|
||||
if got := runtime.cacheTTL(cacheNamespaceGroupSettings); got != 5*time.Minute {
|
||||
t.Fatalf("cache TTL for group settings = %v, want 5m", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidateSubscriptionCacheWithZeroUserDeletesTopicPrefix(t *testing.T) {
|
||||
oldRuntime := groupMsgRuntime
|
||||
runtime := newTestGroupMessageRuntime()
|
||||
groupMsgRuntime = runtime
|
||||
t.Cleanup(func() { groupMsgRuntime = oldRuntime })
|
||||
|
||||
invalidateSubscriptionCache(7, "grpAlpha", types.ZeroUid)
|
||||
want := []string{"grpAlpha:", "chnAlpha:"}
|
||||
if len(runtime.deletedPrefixes) != len(want) || runtime.deletedPrefixes[0] != want[0] || runtime.deletedPrefixes[1] != want[1] {
|
||||
t.Fatalf("unexpected deleted prefixes: %#v", runtime.deletedPrefixes)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user