update cache system

优化缓存系统的存储目录结构。
pull/82/head
hevinci 2023-03-01 20:35:01 +08:00
parent 295238cbb6
commit ab96f3f28c
5 changed files with 63 additions and 34 deletions

View File

@ -23,6 +23,15 @@ namespace YooAsset
_cachedDic.Clear(); _cachedDic.Clear();
} }
/// <summary>
/// 获取缓存文件总数
/// </summary>
public static int GetCachedFilesCount(string packageName)
{
var cache = GetOrCreateCache(packageName);
return cache.GetCachedFilesCount();
}
/// <summary> /// <summary>
/// 查询是否为验证文件 /// 查询是否为验证文件
/// </summary> /// </summary>

View File

@ -101,17 +101,21 @@ namespace YooAsset
if (isFindItem == false) if (isFindItem == false)
break; break;
var fileFoder = _bundleFilesEnumerator.Current; var rootFoder = _bundleFilesEnumerator.Current;
string cacheGUID = fileFoder.Name; var childDirectories = rootFoder.GetDirectories();
if (CacheSystem.IsCached(_packageName, cacheGUID)) foreach(var chidDirectory in childDirectories)
continue; {
string cacheGUID = chidDirectory.Name;
if (CacheSystem.IsCached(_packageName, cacheGUID))
continue;
// 创建验证元素类 // 创建验证元素类
string fileRootPath = fileFoder.FullName; string fileRootPath = chidDirectory.FullName;
string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}"; string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}";
string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}"; string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}";
VerifyElement element = new VerifyElement(_packageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath); VerifyElement element = new VerifyElement(_packageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath);
VerifyElements.Add(element); VerifyElements.Add(element);
}
if (OperationSystem.IsBusy) if (OperationSystem.IsBusy)
break; break;
@ -131,32 +135,35 @@ namespace YooAsset
if (isFindItem == false) if (isFindItem == false)
break; break;
var fileFoder = _rawFilesEnumerator.Current; var rootFoder = _rawFilesEnumerator.Current;
string cacheGUID = fileFoder.Name; var childDirectories = rootFoder.GetDirectories();
if (CacheSystem.IsCached(_packageName, cacheGUID)) foreach (var chidDirectory in childDirectories)
continue;
// 获取数据文件的后缀名
string dataFileExtension = string.Empty;
var fileInfos = fileFoder.GetFiles();
foreach (var fileInfo in fileInfos)
{ {
if (fileInfo.Extension == ".temp") string cacheGUID = chidDirectory.Name;
if (CacheSystem.IsCached(_packageName, cacheGUID))
continue; continue;
if (fileInfo.Name.StartsWith(YooAssetSettings.CacheBundleDataFileName)) // 获取数据文件的后缀名
string dataFileExtension = string.Empty;
var fileInfos = chidDirectory.GetFiles();
foreach (var fileInfo in fileInfos)
{ {
dataFileExtension = fileInfo.Extension; if (fileInfo.Extension == ".temp")
break; continue;
if (fileInfo.Name.StartsWith(YooAssetSettings.CacheBundleDataFileName))
{
dataFileExtension = fileInfo.Extension;
break;
}
} }
}
// 创建验证元素类 // 创建验证元素类
string fileRootPath = fileFoder.FullName; string fileRootPath = chidDirectory.FullName;
string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}{dataFileExtension}"; string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}{dataFileExtension}";
string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}"; string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}";
VerifyElement element = new VerifyElement(_packageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath); VerifyElement element = new VerifyElement(_packageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath);
VerifyElements.Add(element); VerifyElements.Add(element);
}
if (OperationSystem.IsBusy) if (OperationSystem.IsBusy)
break; break;

View File

@ -63,6 +63,9 @@ namespace YooAsset
// 注意:总是返回成功 // 注意:总是返回成功
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
int totalCount = CacheSystem.GetCachedFilesCount(_packageName);
YooLogger.Log($"Package '{_packageName}' cached files count : {totalCount}");
} }
} }
} }

View File

@ -44,6 +44,14 @@ namespace YooAsset
_wrappers.Clear(); _wrappers.Clear();
} }
/// <summary>
/// 获取缓存文件总数
/// </summary>
public int GetCachedFilesCount()
{
return _wrappers.Count;
}
/// <summary> /// <summary>
/// 查询缓存记录 /// 查询缓存记录
/// </summary> /// </summary>

View File

@ -71,15 +71,16 @@ namespace YooAsset
if (string.IsNullOrEmpty(_cachedDataFilePath) == false) if (string.IsNullOrEmpty(_cachedDataFilePath) == false)
return _cachedDataFilePath; return _cachedDataFilePath;
string folderName = FileHash.Substring(0, 2);
if (IsRawFile) if (IsRawFile)
{ {
string cacheRoot = PersistentHelper.GetCachedRawFileFolderPath(PackageName); string cacheRoot = PersistentHelper.GetCachedRawFileFolderPath(PackageName);
_cachedDataFilePath = $"{cacheRoot}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}{_fileExtension}"; _cachedDataFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}{_fileExtension}";
} }
else else
{ {
string cacheRoot = PersistentHelper.GetCachedBundleFileFolderPath(PackageName); string cacheRoot = PersistentHelper.GetCachedBundleFileFolderPath(PackageName);
_cachedDataFilePath = $"{cacheRoot}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}"; _cachedDataFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleDataFileName}";
} }
return _cachedDataFilePath; return _cachedDataFilePath;
} }
@ -96,15 +97,16 @@ namespace YooAsset
if (string.IsNullOrEmpty(_cachedInfoFilePath) == false) if (string.IsNullOrEmpty(_cachedInfoFilePath) == false)
return _cachedInfoFilePath; return _cachedInfoFilePath;
string folderName = FileHash.Substring(0, 2);
if (IsRawFile) if (IsRawFile)
{ {
string cacheRoot = PersistentHelper.GetCachedRawFileFolderPath(PackageName); string cacheRoot = PersistentHelper.GetCachedRawFileFolderPath(PackageName);
_cachedInfoFilePath = $"{cacheRoot}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}"; _cachedInfoFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}";
} }
else else
{ {
string cacheRoot = PersistentHelper.GetCachedBundleFileFolderPath(PackageName); string cacheRoot = PersistentHelper.GetCachedBundleFileFolderPath(PackageName);
_cachedInfoFilePath = $"{cacheRoot}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}"; _cachedInfoFilePath = $"{cacheRoot}/{folderName}/{CacheGUID}/{YooAssetSettings.CacheBundleInfoFileName}";
} }
return _cachedInfoFilePath; return _cachedInfoFilePath;
} }