Files
UnrealEngineUWP/Engine/Source/Developer/DerivedDataCache/Public/DerivedDataCacheKey.h
devin doucette 53f316587b DDC: New filesystem cache store directory layout and file format
- Implemented only for the structured cache initially.
- Records are stored as compact binary packages with payloads stored within the record if small enough.
- Records are stored in Records/{Bucket}/{01}/{23}/{456789abcdef0123456789abcdef01234567} based on the hash in the cache key.
- Content that exceeds the size allowed for storage within the record is stored in Content/{01}/{23}/{456789abcdef0123456789abcdef01234567} based on the hash of the content.
- Both records and content are written to disk with their hash as a suffix, and are always checked on load.
- Maximum size of compressed data stored in the package can be configured by MaxRecordSizeKB and MaxValueSizeKB.
- Maintenance of the cache, to delete unused files, has been rewritten and can now scan ~175k files/second on modern hardware, though is limited to 10k files/second in the config to avoid adding too much overhead.

#rb Zousar.Shaker
#preflight 618b75c14a0c609a29204032
#preflight 618bfb5ec717ba4e929b7ac0

#ROBOMERGE-AUTHOR: devin.doucette
#ROBOMERGE-SOURCE: CL 18133085 in //UE5/Release-5.0/... via CL 18133356
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v889-18060218)
#ROBOMERGE[STARSHIP]: UE5-Main

[CL 18133430 by devin doucette in ue5-release-engine-test branch]
2021-11-10 13:08:00 -05:00

129 lines
3.7 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreTypes.h"
#include "Containers/StringFwd.h"
#include "Containers/StringView.h"
#include "IO/IoHash.h"
#include "Templates/TypeHash.h"
#define UE_API DERIVEDDATACACHE_API
namespace UE::DerivedData
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* An alphanumeric identifier that groups related cache records.
*
* A cache bucket name must be alphanumeric, non-empty, and contain fewer than 256 code units.
*/
class FCacheBucket
{
public:
/** Construct a null cache bucket. */
FCacheBucket() = default;
/** Create a cache bucket from a name. */
UE_API explicit FCacheBucket(FUtf8StringView Name);
UE_API explicit FCacheBucket(FWideStringView Name);
/** Whether this is null. */
inline bool IsNull() const { return !Name; }
/** Whether this is not null. */
inline bool IsValid() const { return !IsNull(); }
/** Reset this to null. */
inline void Reset() { *this = FCacheBucket(); }
inline bool operator==(FCacheBucket Other) const { return Name == Other.Name; }
inline bool operator!=(FCacheBucket Other) const { return Name != Other.Name; }
inline bool operator<(FCacheBucket Other) const
{
return Name != Other.Name && ToString().Compare(Other.ToString(), ESearchCase::IgnoreCase) < 0;
}
friend inline uint32 GetTypeHash(FCacheBucket Bucket)
{
return ::GetTypeHash(reinterpret_cast<UPTRINT>(Bucket.Name));
}
/** Get the name of the cache bucket as a string. */
inline FAnsiStringView ToString() const;
/** Get the name of the cache bucket as a null-terminated string. */
inline const ANSICHAR* ToCString() const { return Name; }
protected:
static constexpr int32 LengthOffset = -1;
/** Name stored as a null-terminated string preceded by one byte containing its length. */
const ANSICHAR* Name = nullptr;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** A key that uniquely identifies a cache record. */
struct FCacheKey
{
FCacheBucket Bucket;
FIoHash Hash;
/** A key with a null bucket and a zero hash. */
static const FCacheKey Empty;
};
inline const FCacheKey FCacheKey::Empty;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inline FAnsiStringView FCacheBucket::ToString() const
{
return Name ? FAnsiStringView(Name, reinterpret_cast<const uint8*>(Name)[LengthOffset]) : FAnsiStringView();
}
template <typename CharType>
inline TStringBuilderBase<CharType>& operator<<(TStringBuilderBase<CharType>& Builder, const FCacheBucket& Bucket)
{
return Builder << Bucket.ToString();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
inline bool operator==(const FCacheKey& A, const FCacheKey& B)
{
return A.Bucket == B.Bucket && A.Hash == B.Hash;
}
inline bool operator!=(const FCacheKey& A, const FCacheKey& B)
{
return A.Bucket != B.Bucket || A.Hash != B.Hash;
}
inline bool operator<(const FCacheKey& A, const FCacheKey& B)
{
const FCacheBucket& BucketA = A.Bucket;
const FCacheBucket& BucketB = B.Bucket;
return BucketA == BucketB ? A.Hash < B.Hash : BucketA < BucketB;
}
inline uint32 GetTypeHash(const FCacheKey& Key)
{
return HashCombine(GetTypeHash(Key.Bucket), GetTypeHash(Key.Hash));
}
template <typename CharType>
inline TStringBuilderBase<CharType>& operator<<(TStringBuilderBase<CharType>& Builder, const FCacheKey& Key)
{
return Builder << Key.Bucket << CharType('/') << Key.Hash;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
} // UE::DerivedData
#undef UE_API