fix
This commit is contained in:
@@ -35,9 +35,17 @@ type CacheInfo struct {
|
||||
|
||||
// NewPDFCacheManager 创建PDF缓存管理器
|
||||
func NewPDFCacheManager(logger *zap.Logger, cacheDir string, ttl time.Duration, maxSize int64) (*PDFCacheManager, error) {
|
||||
// 如果缓存目录为空,使用默认目录
|
||||
// 如果缓存目录为空,使用项目根目录的storage/component-reports/cache目录
|
||||
if cacheDir == "" {
|
||||
cacheDir = filepath.Join(os.TempDir(), "tyapi_pdf_cache")
|
||||
// 获取当前工作目录并构建项目根目录路径
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
// 如果获取工作目录失败,回退到临时目录
|
||||
cacheDir = filepath.Join(os.TempDir(), "tyapi_pdf_cache")
|
||||
} else {
|
||||
// 构建项目根目录下的storage/component-reports/cache路径
|
||||
cacheDir = filepath.Join(wd, "storage", "component-reports", "cache")
|
||||
}
|
||||
}
|
||||
|
||||
// 确保缓存目录存在
|
||||
@@ -60,7 +68,6 @@ func NewPDFCacheManager(logger *zap.Logger, cacheDir string, ttl time.Duration,
|
||||
zap.Duration("ttl", ttl),
|
||||
zap.Int64("max_size", maxSize),
|
||||
)
|
||||
|
||||
return manager, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user