Data file handling
This commit is contained in:
+27
-18
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user