UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
CacheJournal.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "IO/IoChunkId.h"
6#include "IO/IoHash.h"
8#include "Containers/Array.h"
9#include "Math/Interval.h"
11
12#if !UE_BUILD_SHIPPING
13
15{
17 {
18 TOptional<uint64> ModTag; // content modification tag
19 TOptional<int64> RawSize; // size of complete chunk
20 TOptional<int32> RawBlockSize; // size of block in a chunk if any, e.g. 256kb, can be 0
21
26 )
27 {
28 bool bResult = true;
29 if (OptModTag)
30 {
31 bResult = ModTag.IsSet() ? *ModTag == *OptModTag : true;
33 }
34 if (OptRawSize)
35 {
37 }
39 {
41 }
42 return bResult;
43 }
44
46 {
47 ModTag = Other.ModTag;
48 RawSize = Other.RawSize;
49 RawBlockSize = Other.RawBlockSize;
50 return *this;
51 }
52
54 {
55 Ar << Info.ModTag;
56 Ar << Info.RawSize;
57 Ar << Info.RawBlockSize;
58 return Ar;
59 }
60 };
61
63 {
64 uint64 ChunkOffset; // uncompressed offset in a chunk
65 uint64 ChunkSize; // uncompressed size in a chunk
66 uint64 StorageOffset; // offset in cache storage
67 uint64 StorageSize; // size in cache storage
68 FIoHash StorageHash; // hash of data in cache storage, needed to validate after reading from storage as we might lose data
70
75
77 {
78 Ar << Entry.ChunkOffset;
79 Ar << Entry.ChunkSize;
80 Ar << Entry.StorageOffset;
81 Ar << Entry.StorageSize;
82 Ar << Entry.StorageHash;
83 Ar << Entry.StorageContentType;
84 return Ar;
85 }
86 };
87
88 // Generic journal for storage server caching. Transactions are thread safe, atomic, saved at best effort.
89 // Cache journal focuses on avoiding data corruption when saving to disk, unlike cache storage which doesn't provide any guarantees for data consistency.
91 {
92 public:
93 virtual ~ICacheJournal() = default;
94
95 // Flushes data to backing storage
96 virtual void Flush(bool bImmediate) = 0;
97
98 // Invalidates all data in journal
99 virtual void InvalidateAll() = 0;
100
101 // Invalidates data for a specific chunk.
102 virtual void Invalidate(const FIoChunkId& ChunkId) = 0;
103
104 // Updates chunk info. All fields are optional.
105 // If OptModTag is passed will compare it to existing ModTag and asks you to invalidate all data for this chunk id if they don't match.
106 // OptRawSize, OptRawBlockSize will simply be updated if passed.
107 // Returns true if either new ChunkId info is created or ModTag matches previous existing entry for this ChunkId.
108 // Returns false if ModHash doesn't match and cached data for this entry needs to be invalidated.
109 virtual bool SetChunkInfo(
110 const FIoChunkId& ChunkId,
114 ) = 0;
115
116 // Return chunk info if present, returns true if chunk info is present.
117 virtual bool TryGetChunkInfo(
118 const FIoChunkId& ChunkId,
120 ) = 0;
121
122 // Adds a new cache entry for chunk.
123 // Returns true if new entry was added, false if there is an entry for (ChunkId / ChunkOffset / ChunkSize).
124 virtual bool AddEntry(
125 const FIoChunkId& ChunkId,
126 const FCacheEntry& Entry
127 ) = 0;
128
129 // Tries to find an entry for specified chunk offset and size, returns true if entry is present.
130 virtual bool TryGetEntry(
131 const FIoChunkId& ChunkId,
132 const uint64 ChunkOffset,
133 const uint64 ChunkSize,
135 ) = 0;
136
137 // Iterate chunk id in journal that contain at least one entry.
138 // Not safe to invoke other journal methods from the callback.
139 virtual void IterateChunkIds(
140 TFunctionRef<void(const FIoChunkId& ChunkId, const FCacheChunkInfo& ChunkInfo)> Callback
141 ) = 0;
142
143 // Iterate entries for a chunk id in journal.
144 // Not safe to invoke other journal methods from the callback.
146 const FIoChunkId& ChunkId,
147 TFunctionRef<void(const FCacheEntry& Entry)> Callback
148 ) = 0;
149
150 // Iterate all entries in journal.
151 // Not safe to invoke other journal methods from the callback.
153 TFunctionRef<void(const FIoChunkId& ChunkId, const FCacheEntry& Entry)> Callback
154 ) = 0;
155 };
156}
157
158#endif
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
EStorageServerContentType
Definition StorageServerHttpClient.h:13
Definition Archive.h:1208
Definition IoChunkId.h:64
Definition CacheJournal.h:91
virtual void IterateChunkIds(TFunctionRef< void(const FIoChunkId &ChunkId, const FCacheChunkInfo &ChunkInfo)> Callback)=0
virtual bool TryGetEntry(const FIoChunkId &ChunkId, const uint64 ChunkOffset, const uint64 ChunkSize, FCacheEntry &OutEntry)=0
virtual void InvalidateAll()=0
virtual void IterateCacheEntriesForChunkId(const FIoChunkId &ChunkId, TFunctionRef< void(const FCacheEntry &Entry)> Callback)=0
virtual void Flush(bool bImmediate)=0
virtual bool AddEntry(const FIoChunkId &ChunkId, const FCacheEntry &Entry)=0
virtual bool TryGetChunkInfo(const FIoChunkId &ChunkId, FCacheChunkInfo &OutChunkInfo)=0
virtual ~ICacheJournal()=default
virtual void IterateCacheEntries(TFunctionRef< void(const FIoChunkId &ChunkId, const FCacheEntry &Entry)> Callback)=0
virtual bool SetChunkInfo(const FIoChunkId &ChunkId, const TOptional< uint64 > &OptModTag, const TOptional< int64 > &OptRawSize, const TOptional< int32 > &OptRawBlockSize)=0
virtual void Invalidate(const FIoChunkId &ChunkId)=0
Definition AssetRegistryState.h:50
Definition CacheJournal.h:15
Definition IoHash.h:33
Definition CacheJournal.h:17
TOptional< uint64 > ModTag
Definition CacheJournal.h:18
bool SetChunkInfo(const TOptional< uint64 > &OptModTag, const TOptional< int64 > &OptRawSize, const TOptional< int32 > &OptRawBlockSize)
Definition CacheJournal.h:22
TOptional< int32 > RawBlockSize
Definition CacheJournal.h:20
friend FArchive & operator<<(FArchive &Ar, FCacheChunkInfo &Info)
Definition CacheJournal.h:53
FCacheChunkInfo & operator=(const FCacheChunkInfo &Other)
Definition CacheJournal.h:45
TOptional< int64 > RawSize
Definition CacheJournal.h:19
Definition CacheJournal.h:63
EStorageServerContentType StorageContentType
Definition CacheJournal.h:69
uint64 StorageOffset
Definition CacheJournal.h:66
uint64 ChunkSize
Definition CacheJournal.h:65
uint64 ChunkOffset
Definition CacheJournal.h:64
uint64 StorageSize
Definition CacheJournal.h:67
TInterval< uint64 > GetChunkInterval() const
Definition CacheJournal.h:71
FIoHash StorageHash
Definition CacheJournal.h:68
friend FArchive & operator<<(FArchive &Ar, FCacheEntry &Entry)
Definition CacheJournal.h:76
Definition Interval.h:33
Definition Optional.h:131
constexpr bool IsSet() const
Definition Optional.h:69