CreateDiskCacheFile 创建磁盘缓存文件 cacheType: 缓存类型(body/file) 返回文件路径和文件句柄
(cacheType DiskCacheType)
| 40 | // cacheType: 缓存类型(body/file) |
| 41 | // 返回文件路径和文件句柄 |
| 42 | func CreateDiskCacheFile(cacheType DiskCacheType) (string, *os.File, error) { |
| 43 | if err := EnsureDiskCacheDir(); err != nil { |
| 44 | return "", nil, fmt.Errorf("failed to create cache directory: %w", err) |
| 45 | } |
| 46 | |
| 47 | dir := GetDiskCacheDir() |
| 48 | filename := fmt.Sprintf("%s-%s-%d.tmp", cacheType, uuid.New().String()[:8], time.Now().UnixNano()) |
| 49 | filePath := filepath.Join(dir, filename) |
| 50 | |
| 51 | file, err := os.OpenFile(filePath, os.O_CREATE|os.O_RDWR|os.O_EXCL, 0600) |
| 52 | if err != nil { |
| 53 | return "", nil, fmt.Errorf("failed to create cache file: %w", err) |
| 54 | } |
| 55 | |
| 56 | return filePath, file, nil |
| 57 | } |
| 58 | |
| 59 | // WriteDiskCacheFile 写入数据到磁盘缓存文件 |
| 60 | // 返回文件路径 |
no test coverage detected