MCPcopy Create free account
hub / github.com/QuantumNous/new-api / CreateDiskCacheFile

Function CreateDiskCacheFile

common/disk_cache.go:42–57  ·  view source on GitHub ↗

CreateDiskCacheFile 创建磁盘缓存文件 cacheType: 缓存类型(body/file) 返回文件路径和文件句柄

(cacheType DiskCacheType)

Source from the content-addressed store, hash-verified

40// cacheType: 缓存类型(body/file)
41// 返回文件路径和文件句柄
42func 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// 返回文件路径

Callers 3

WriteDiskCacheFileFunction · 0.85
newDiskStorageFunction · 0.85
newDiskStorageFromReaderFunction · 0.85

Calls 3

EnsureDiskCacheDirFunction · 0.85
GetDiskCacheDirFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected