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

@@ -174,11 +174,11 @@ func (l *Logic) registerDefaultJobs(ctx context.Context) error {
}
// 每30分钟执行一次OSS预签名URL缓存刷新任务
if err := l.AddJob(ctx, "oss_presignurl_refresh", "0 0/30 * * * *", func() {
l.refreshOssPresignUrlCacheJob(ctx)
}); err != nil {
return err
}
//if err := l.AddJob(ctx, "oss_presignurl_refresh", "0 0/30 * * * *", func() {
// l.refreshOssPresignUrlCacheJob(ctx)
//}); err != nil {
// return err
//}
return nil
}

View File

@@ -130,6 +130,12 @@ func (l *Logic) GetHeroDetailByCode(ctx context.Context, code string) (*v1.HeroD
if err != nil {
return nil, err
}
if util.RedisCache == nil {
panic("util.RedisCache is nil")
}
if fribbleHeroSet == nil {
panic("fribbleHeroSet is nil")
}
// 写入 Redis 缓存1小时
util.RedisCache.Set(ctx, cacheKey, fribbleHeroSet.JsonContent, 0)
}

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