feat: add kafka admin integration
This commit is contained in:
@@ -2,6 +2,7 @@ package store
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -42,6 +43,18 @@ func (c *configCache[T]) set(key string, value T) {
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *configCache[T]) delete(key string) {
|
||||
c.mu.Lock()
|
||||
delete(c.items, key)
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *configCache[T]) clear() {
|
||||
c.mu.Lock()
|
||||
c.items = make(map[string]configCacheEntry[T])
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
var (
|
||||
tenantByCodeCache = newConfigCache[*types.Tenant]()
|
||||
tenantByIDCache = newConfigCache[*types.Tenant]()
|
||||
@@ -83,3 +96,43 @@ func thirdPartyCacheKey(group string, keys ...string) string {
|
||||
sort.Strings(normalized)
|
||||
return group + ":" + strings.Join(normalized, ",")
|
||||
}
|
||||
|
||||
// InvalidateTenantConfigCache clears cached tenant registry/config records. An
|
||||
// empty selector clears all tenant records.
|
||||
func InvalidateTenantConfigCache(code string, id types.TenantID) {
|
||||
if strings.TrimSpace(code) != "" {
|
||||
tenantByCodeCache.delete(strings.TrimSpace(code))
|
||||
} else {
|
||||
tenantByCodeCache.clear()
|
||||
}
|
||||
if id.IsValid() {
|
||||
tenantByIDCache.delete(formatTenantIDForCache(id))
|
||||
} else if strings.TrimSpace(code) == "" {
|
||||
tenantByIDCache.clear()
|
||||
}
|
||||
}
|
||||
|
||||
// InvalidateRegistrationConfigCache clears cached global registration config.
|
||||
func InvalidateRegistrationConfigCache() {
|
||||
registrationSMSCache.clear()
|
||||
}
|
||||
|
||||
// InvalidateThirdPartyConfigCache clears cached third-party config.
|
||||
func InvalidateThirdPartyConfigCache(group string) {
|
||||
if strings.TrimSpace(group) == "" {
|
||||
thirdPartyConfigCache.clear()
|
||||
return
|
||||
}
|
||||
prefix := strings.TrimSpace(group) + ":"
|
||||
thirdPartyConfigCache.mu.Lock()
|
||||
for key := range thirdPartyConfigCache.items {
|
||||
if strings.HasPrefix(key, prefix) {
|
||||
delete(thirdPartyConfigCache.items, key)
|
||||
}
|
||||
}
|
||||
thirdPartyConfigCache.mu.Unlock()
|
||||
}
|
||||
|
||||
func formatTenantIDForCache(id types.TenantID) string {
|
||||
return strconv.FormatInt(int64(id), 10)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user