Files
UnrealEngineUWP/Engine/Source/Developer/DerivedDataCache/Public/DerivedDataCacheRecord.h
Devin Doucette 7bd5b197e8 DDC: Added the new cache interface UE::DerivedData::ICache
ICache will eventually replace the existing cache access functions on FDerivedDataCacheInterface. The notable differences relative to the existing interface are:

- It is asynchronous with completion callbacks by default, and allows waiting when necessary.
- It allows batch requests containing multiple cache records by default.
- It uses a structured cache key made up of a bucket name and a hash.
- It supports prioritization and cancellation of requests.
- It supports structured cache records with metadata.
- It supports attachments to allow multi-part cache records.
- It uses a typed request object instead of an opaque integer handle.
- It provides cache policy flags to control how to query and store cache records, and which parts of a cache record to fetch.

This initial implementation of ICache is totally synchronous and uses the existing cache backends for storage.

#rb Zousar.Shaker

[CL 15152247 by Devin Doucette in ue5-main branch]
2021-01-21 01:57:01 -04:00

83 lines
2.3 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreTypes.h"
#include "DerivedDataCacheKey.h"
#include "Memory/SharedBuffer.h"
#include "Serialization/CompactBinary.h"
#include "Serialization/CompactBinaryPackage.h"
#define UE_API DERIVEDDATACACHE_API
namespace UE
{
namespace DerivedData
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** The type of value stored in a cache record. */
enum class ECacheRecordType : uint8
{
None,
Binary,
Object,
Package,
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* A cache record is a key, metadata, and a value.
*
* The value may be one of binary, object, or package.
*/
class FCacheRecord
{
public:
/** Construct an empty cache record. */
UE_API FCacheRecord();
/** Reset to an empty record. */
UE_API void Reset();
inline const FCacheKey& GetKey() const { return Key; }
inline void SetKey(const FCacheKey& InKey) { Key = InKey; }
inline const FCbObjectRef& GetMeta() const { return Meta; }
inline void SetMeta(FCbObjectRef InMeta) { Meta = MoveTemp(InMeta); }
inline ECacheRecordType GetType() const { return Type; }
/** Access the value as binary. Returns a null buffer if not binary. */
inline const FSharedBuffer& AsBinary() const { return Binary; }
/** Access the value as an object. Returns an empty object if not an object. */
inline const FCbObjectRef& AsObject() const { return Object; }
/** Access the value as a package. Returns a null package if not a package. */
inline const FCbPackage& AsPackage() const { return Package; }
/** Set the value as binary. Removes any existing value of another type. */
UE_API void SetBinary(FSharedBuffer Value);
/** Set the value as an object. Removes any existing value of another type. */
UE_API void SetObject(FCbObjectRef Value);
/** Set the value as a package. Removes any existing value of another type. */
UE_API void SetPackage(FCbPackage Value);
private:
FCacheKey Key;
FCbObjectRef Meta;
FSharedBuffer Binary;
FCbObjectRef Object;
FCbPackage Package;
ECacheRecordType Type = ECacheRecordType::None;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
} // DerivedData
} // UE
#undef UE_API