Data file handling

This commit is contained in:
Michael Schimmel
2025-06-15 20:07:18 +02:00
parent 2c56f6e750
commit f81337c98d
3 changed files with 268 additions and 246 deletions
+27 -18
View File
@@ -100,26 +100,35 @@ begin
FLock.Enter;
try
// Caching is active. First, try to free memory if needed.
fileList := FCachedFiles.Values.ToArray;
TArray.Sort<TCachedFile>(
fileList,
TComparer<TCachedFile>.Construct(
function(const Left, Right: TCachedFile): Integer
begin
// Sort by LastUsed timestamp, oldest first.
Result := Sign(Left.LastUsed - Right.LastUsed);
end
)
);
for i := 0 to High(fileList) do
if IsMemoryLow() then
begin
if not IsMemoryLow() then
break; // Stop evicting if memory pressure is relieved.
// Caching is active. First, try to free memory if needed.
fileList := FCachedFiles.Values.ToArray;
TArray.Sort<TCachedFile>(
fileList,
TComparer<TCachedFile>.Construct(
function(const Left, Right: TCachedFile): Integer
begin
// Sort by LastUsed timestamp, oldest first.
Result := Sign(Left.LastUsed - Right.LastUsed);
end
)
);
if fileList[i].Name <> AFileName then
FCachedFiles.Remove(fileList[i].Name);
for i := 0 to High(fileList) do
begin
if not IsMemoryLow() then
break; // Stop evicting if memory pressure is relieved.
if fileList[i].Name <> AFileName then
begin
if fileList[i].Data.Done.IsSet then
begin
FCachedFiles.Remove(fileList[i].Name);
fileList[i].Data := TFuture<T>.Null;
end;
end;
end;
end;
// Check if a valid entry exists in the cache.