Files
UnrealEngine/Engine/Source/Runtime/Experimental/IndexedCacheStorage/Public/IndexedCacheStorageManager.h
2025-05-18 13:04:45 +08:00

93 lines
2.6 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "Containers/Array.h"
#include "Containers/Map.h"
#include "HAL/Platform.h"
#include "HAL/CriticalSection.h"
#include "Containers/UnrealString.h"
#define UE_API INDEXEDCACHESTORAGE_API
namespace Experimental
{
// Manager to handle ref-counting of ICS entries
class FIndexedCacheStorageManager
{
public:
UE_API static FIndexedCacheStorageManager& Get();
// Returns whether ICS is supported
UE_API bool SupportsIndexedCacheStorage();
// Returns the cache index registered to that storage name. Registration happens in the config section:
// [IndexedCacheStorage]
// (Name="StorageName",Index=StorageIndex,Mount="StorageMount")
UE_API int32 GetStorageIndex(const FString& CacheStorageName);
// returns all registered storage names. The assoaciated cache storages might not have been created
UE_API void EnumerateCacheStorages(TArray<FString>& OutCacheStorageNames);
// Create a new storage at the specified index. Will destroy the previous one if it had a different capacity
UE_API bool CreateCacheStorage(uint64 RequestNumberOfBytes, int32 CacheIndex);
// Destroy the specified cache storage
UE_API void DestroyCacheStorage(int32 CacheIndex);
// Returns 0 if no cache currently exists
UE_API uint64 GetCacheStorageCapacity(int32 CacheIndex);
// Returns the path of the mounted cache
UE_API FString MountCacheStorage(int32 CacheIndex);
// Requests unmounting for CacheIndex. Actually unmounts if # of UnmountCacheEntry == # of MountCacheStorage for the same index
UE_API void UnmountCacheStorage(int32 CacheIndex);
// Returns mount name in cache index is mounted, empty if not mounted
UE_API FString GetMountName(int32 CacheIndex);
// Helper to retrieve the mount path. Equivalent to GetCacheStorageMountPath(GetMountName)
UE_API FString GetMountPath(int32 CacheIndex);
private:
void Initialize();
FRWLock IndexedCacheEntriesMetaDataLock;
struct FCacheStorageMetaData
{
FString MountName;
int32 MountRefCount = 0;
bool bCacheExists = false;
};
TArray<FCacheStorageMetaData> IndexedCacheEntriesMetaData;
TMap<FString, int32> StorageNameToStorageIndex;
bool bHasRegisteredEntries = false;
};
struct FIndexedCacheStorageScopeMount
{
FIndexedCacheStorageScopeMount(int32 InMountPoint)
: MountPoint(InMountPoint)
{
MountPath = Experimental::FIndexedCacheStorageManager::Get().MountCacheStorage(MountPoint);
}
~FIndexedCacheStorageScopeMount()
{
Experimental::FIndexedCacheStorageManager::Get().UnmountCacheStorage(MountPoint);
}
FString MountPath;
const int32 MountPoint = 0;
};
}
#undef UE_API