UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
InstallBundleCache.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
6#include "Containers/Map.h"
8#include "HAL/Platform.h"
10#include "Misc/DateTime.h"
11#include "Misc/Optional.h"
12#include "Misc/Timespan.h"
14#include "UObject/NameTypes.h"
15
17
23
25{
27 uint64 FullInstallSize = 0; // Total disk footprint when this bundle is fully installed
28 uint64 InstallOverheadSize = 0; // Any extra space required to update the bundle
29 uint64 CurrentInstallSize = 0; // Disk footprint of the bundle in it's current state
30 FDateTime TimeStamp = FDateTime::MinValue(); // Last access time for the bundle. Used for eviction order
31 double AgeScalar = 1.0; // Allow some bundles to "age" slower than others
32};
33
35{
36 Fail_CacheFull, // Cache is full and it's not possible to evict anything else from the cache
37 Fail_NeedsEvict, // Cache is full but it' possible to evict released bundles to make room for this one
38 Fail_PendingEvict, // This bundle can't be reserved because it's currently being evicted
39 Success, // Bundle was reserved successfully
40};
41
47
52
53class FInstallBundleCache : public TSharedFromThis<FInstallBundleCache>
54{
55public:
57
59
60 FName GetName() const { return CacheName; }
61
62 // Add a bundle to the cache.
64
66
69
70 // Return the total size of the cache
72 // Return the amount of space in use. This could possbly exceed GetSize() if the cache size is changed or more
73 // bundles are added the to cache.
75 // Return the amount of free space in the cache, clamped to [0, GetSize()]
77
78 // Called from bundle manager
80
81 // Called from bundle manager, returns all bundles that can be evicted
83
84 INSTALLBUNDLEMANAGER_API bool Contains(FName BundleName) const;
86
87 INSTALLBUNDLEMANAGER_API bool IsReserved(FName BundleName) const;
88
89 // Called from bundle manager to make the files for this bundle eligible for eviction
90 INSTALLBUNDLEMANAGER_API bool Release(FName BundleName);
91
93
95
96 // Hint to the cache that this bundle is requested, and we should prefer to evict non-requested bundles if possible
97 INSTALLBUNDLEMANAGER_API void HintRequested(FName BundleName, bool bRequested);
98
100
101private:
102 INSTALLBUNDLEMANAGER_API uint64 GetFreeSpaceInternal(uint64 UsedSize) const;
103
104 INSTALLBUNDLEMANAGER_API void CheckInvariants() const;
105
106 INSTALLBUNDLEMANAGER_API void UpdateCacheInfoFromSourceInfo(FName BundleName);
107
108private:
109 struct FPerSourceBundleCacheInfo
110 {
111 uint64 FullInstallSize = 0;
112 uint64 InstallOverheadSize = 0;
113 uint64 CurrentInstallSize = 0;
114 FDateTime TimeStamp = FDateTime::MinValue();
115 double AgeScalar = 1.0;
116 };
117
118 enum class ECacheState : uint8
119 {
120 Released, //Transitions to Reserved or PendingEvict
121 Reserved, //Transitions to Released
122 PendingEvict, // Transitions to Released
123 };
124
125 struct FBundleCacheInfo
126 {
127 uint64 FullInstallSize = 0;
128 uint64 InstallOverheadSize = 0;
129 uint64 CurrentInstallSize = 0;
131 double AgeScalar = 1.0;
132 ECacheState State = ECacheState::Released;
133 int32 HintReqeustedCount = 0; // Hint to the cache that this bundle is requested, and we should prefer to evict non-requested bundles if possible
134
135 bool IsHintRequested() const { return HintReqeustedCount > 0; }
136
137 uint64 GetSize() const
138 {
139 if (State == ECacheState::Released)
140 return CurrentInstallSize;
141
142 // Just consider any pending evictions to be 0 size.
143 // Bundle Manager will still wait on them if necessary when reserving.
144 if (State == ECacheState::PendingEvict)
145 return 0;
146
147 if (CurrentInstallSize > FullInstallSize)
148 return CurrentInstallSize + InstallOverheadSize;
149
150 return FullInstallSize + InstallOverheadSize;
151 }
152 };
153
154 struct FCacheSortPredicate
155 {
156 bool operator()(const FBundleCacheInfo& A, const FBundleCacheInfo& B) const
157 {
158 if (A.IsHintRequested() == B.IsHintRequested())
159 {
160 FTimespan AgeA = (Now > A.TimeStamp) ? Now - A.TimeStamp : FTimespan(0);
161 FTimespan AgeB = (Now > B.TimeStamp) ? Now - B.TimeStamp : FTimespan(0);
162
163 return AgeA * A.AgeScalar > AgeB * B.AgeScalar;
164 }
165
166 return !A.IsHintRequested() && B.IsHintRequested();
167 };
168
169 private:
171 };
172
173private:
174
176
177 // mutable to allow sorting in const contexts
178 mutable TMap<FName, FBundleCacheInfo> CacheInfo;
179
180 uint64 TotalSize = 0;
181
182 FName CacheName;
183};
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
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
EInstallBundleCacheReserveResult
Definition InstallBundleCache.h:35
EInstallBundleCacheStatsFlags
Definition InstallBundleTypes.h:488
void Init()
Definition LockFreeList.h:4
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition InstallBundleCache.h:54
INSTALLBUNDLEMANAGER_API bool SetPendingEvict(FName BundleName)
Definition InstallBundleCache.cpp:302
INSTALLBUNDLEMANAGER_API uint64 GetSize() const
Definition InstallBundleCache.cpp:91
INSTALLBUNDLEMANAGER_API bool Contains(FName BundleName) const
Definition InstallBundleCache.cpp:251
INSTALLBUNDLEMANAGER_API FInstallBundleCacheStats GetStats(EInstallBundleCacheStatsFlags Flags=EInstallBundleCacheStatsFlags::None, bool bVerbose=false) const
Definition InstallBundleCache.cpp:395
virtual INSTALLBUNDLEMANAGER_API ~FInstallBundleCache()
Definition InstallBundleCache.cpp:9
INSTALLBUNDLEMANAGER_API FInstallBundleCacheReserveResult Reserve(FName BundleName)
Definition InstallBundleCache.cpp:125
INSTALLBUNDLEMANAGER_API uint64 GetUsedSize() const
Definition InstallBundleCache.cpp:96
INSTALLBUNDLEMANAGER_API bool IsReserved(FName BundleName) const
Definition InstallBundleCache.cpp:267
FName GetName() const
Definition InstallBundleCache.h:60
INSTALLBUNDLEMANAGER_API uint64 GetFreeSpace() const
Definition InstallBundleCache.cpp:117
INSTALLBUNDLEMANAGER_API void AddOrUpdateBundle(FInstallBundleSourceType Source, const FInstallBundleCacheBundleInfo &AddInfo)
Definition InstallBundleCache.cpp:19
INSTALLBUNDLEMANAGER_API void RemoveBundle(FInstallBundleSourceType Source, FName BundleName)
Definition InstallBundleCache.cpp:35
INSTALLBUNDLEMANAGER_API bool ClearPendingEvict(FName BundleName)
Definition InstallBundleCache.cpp:326
INSTALLBUNDLEMANAGER_API void HintRequested(FName BundleName, bool bRequested)
Definition InstallBundleCache.cpp:350
INSTALLBUNDLEMANAGER_API TOptional< FInstallBundleCacheBundleInfo > GetBundleInfo(FName BundleName) const
Definition InstallBundleCache.cpp:50
Definition InstallBundleTypes.h:47
Definition NameTypes.h:617
Definition UnrealString.h.inl:34
Definition SharedPointer.h:1640
@ TimeStamp
Definition AutomationAnalyticParams.h:23
@ Reserved
Definition MemPro.h:148
State
Definition PacketHandler.h:88
Definition DateTime.h:76
static CORE_API FDateTime UtcNow()
Definition DateTime.cpp:980
static FDateTime MinValue()
Definition DateTime.h:668
Definition InstallBundleCache.h:25
uint64 FullInstallSize
Definition InstallBundleCache.h:27
double AgeScalar
Definition InstallBundleCache.h:31
uint64 CurrentInstallSize
Definition InstallBundleCache.h:29
FName BundleName
Definition InstallBundleCache.h:26
FDateTime TimeStamp
Definition InstallBundleCache.h:30
uint64 InstallOverheadSize
Definition InstallBundleCache.h:28
Definition InstallBundleCache.h:49
TMap< FName, TArray< FInstallBundleSourceType > > BundlesToEvict
Definition InstallBundleCache.h:50
Definition InstallBundleCache.h:19
uint64 Size
Definition InstallBundleCache.h:21
FName CacheName
Definition InstallBundleCache.h:20
Definition InstallBundleCache.h:43
EInstallBundleCacheReserveResult Result
Definition InstallBundleCache.h:45
TMap< FName, TArray< FInstallBundleSourceType > > BundlesToEvict
Definition InstallBundleCache.h:44
Definition InstallBundleTypes.h:477
Definition Timespan.h:76
Definition Optional.h:131