feat(api): refactor cache key handling for server and user lists

This commit is contained in:
Chang lue Tsen
2025-08-31 11:29:55 -04:00
parent 82fd674ae4
commit 6dc1bee14c
8 changed files with 143 additions and 38 deletions
+7 -6
View File
@@ -5,8 +5,6 @@ import (
"errors"
"fmt"
"github.com/perfect-panel/server/internal/config"
"github.com/perfect-panel/server/pkg/cache"
"github.com/redis/go-redis/v9"
"gorm.io/gorm"
@@ -62,20 +60,23 @@ func (m *defaultServerModel) batchGetCacheKeys(Servers ...*Server) []string {
return keys
}
func (m *defaultServerModel) getCacheKeys(data *Server) []string {
if data == nil {
return []string{}
}
detailsKey := fmt.Sprintf("%s%v", CacheServerDetailPrefix, data.Id)
ServerIdKey := fmt.Sprintf("%s%v", cacheServerIdPrefix, data.Id)
configIdKey := fmt.Sprintf("%s%v", config.ServerConfigCacheKey, data.Id)
userIDKey := fmt.Sprintf("%s%d", config.ServerUserListCacheKey, data.Id)
//configIdKey := fmt.Sprintf("%s%v", config.ServerConfigCacheKey, data.Id)
//userIDKey := fmt.Sprintf("%s%d", config.ServerUserListCacheKey, data.Id)
// query protocols to get config keys
cacheKeys := []string{
ServerIdKey,
detailsKey,
configIdKey,
userIDKey,
//configIdKey,
//userIDKey,
}
return cacheKeys
}
+3 -4
View File
@@ -5,7 +5,6 @@ import (
"fmt"
"strings"
"github.com/perfect-panel/server/internal/config"
"gorm.io/gorm"
)
@@ -45,10 +44,10 @@ var (
// ClearCache Clear Cache
func (m *customServerModel) ClearCache(ctx context.Context, id int64) error {
serverIdKey := fmt.Sprintf("%s%v", cacheServerIdPrefix, id)
configKey := fmt.Sprintf("%s%d", config.ServerConfigCacheKey, id)
userListKey := fmt.Sprintf("%s%v", config.ServerUserListCacheKey, id)
//configKey := fmt.Sprintf("%s%d", config.ServerConfigCacheKey, id)
//userListKey := fmt.Sprintf("%s%v", config.ServerUserListCacheKey, id)
return m.DelCacheCtx(ctx, serverIdKey, configKey, userListKey)
return m.DelCacheCtx(ctx, serverIdKey)
}
// QueryServerCountByServerGroups Query Server Count By Server Groups