refactor(internal): 优化 OSS 预签名 URL 缓存刷新任务和英雄数据缓存逻辑

- 注释掉 OSS预签名 URL 缓存刷新任务的定时执行代码
- 在 hero/hero.go 中增加对 Redis缓存和英雄数据集的非空校验
- 修改 OSS预签名 URL 生成逻辑,自动替换为 CDN 域名
This commit is contained in:
hu xiaotong
2025-07-17 16:11:36 +08:00
parent 7b7f8c31d7
commit 8ab1379cae
4 changed files with 19 additions and 20 deletions

View File

@@ -7,6 +7,7 @@ import (
"io"
"net/http"
"os"
"strings"
"sync"
"time"
@@ -146,11 +147,12 @@ func RefreshOssPresignedUrlCache(ctx context.Context, keys []string, expire time
}
// 缓存到Rediskey可加前缀区分
cacheKey := "oss:presignurl:" + key
if err := RedisCache.Set(ctx, cacheKey, presignResult.URL, expire); err != nil {
// 自动生成CDN域名的预签名可访问地址
cdnPresignedUrl := strings.Replace(presignResult.URL, "https://"+bucket+".s3.bitiful.net", "https://bfoss.htoop.cn", 1)
fmt.Printf("CDN预签名可访问地址: %s\n", cdnPresignedUrl)
// 写入Redis时也用CDN域名的预签名地址
if err := RedisCache.Set(ctx, cacheKey, cdnPresignedUrl, expire); err != nil {
Error(ctx, "写入Redis失败", cacheKey, err)
} else {
// 打印预签名可访问地址
fmt.Printf("预签名可访问地址: %s\n", presignResult.URL)
}
}
return nil