Fixed cache issues because conflicts
This commit is contained in:
@@ -259,8 +259,6 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
||||
|
||||
private CancellationTokenSource _penumbraFswCts = new();
|
||||
private CancellationTokenSource _lightlessFswCts = new();
|
||||
private long totalSize;
|
||||
private long maxCacheBytes;
|
||||
|
||||
public FileSystemWatcher? PenumbraWatcher { get; private set; }
|
||||
public FileSystemWatcher? LightlessWatcher { get; private set; }
|
||||
@@ -406,73 +404,71 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
||||
|
||||
public void RecalculateFileCacheSize(CancellationToken token)
|
||||
{
|
||||
var folder = _configService.Current.CacheFolder;
|
||||
if (string.IsNullOrWhiteSpace(folder) || !Directory.Exists(folder))
|
||||
if (string.IsNullOrEmpty(_configService.Current.CacheFolder) ||
|
||||
!Directory.Exists(_configService.Current.CacheFolder))
|
||||
{
|
||||
FileCacheSize = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
FileCacheSize = -1;
|
||||
bool isWine = _dalamudUtil?.IsWine ?? false;
|
||||
|
||||
try
|
||||
{
|
||||
var drive = DriveInfo.GetDrives()
|
||||
.FirstOrDefault(d => folder.StartsWith(d.Name, StringComparison.OrdinalIgnoreCase));
|
||||
.FirstOrDefault(d => _configService.Current.CacheFolder
|
||||
.StartsWith(d.Name, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (drive != null)
|
||||
FileCacheDriveFree = drive.AvailableFreeSpace;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogWarning(ex, "Could not determine drive size for storage folder {folder}", folder);
|
||||
Logger.LogWarning(ex, "Could not determine drive size for storage folder {folder}", _configService.Current.CacheFolder);
|
||||
}
|
||||
|
||||
List<FileInfo> files;
|
||||
try
|
||||
{
|
||||
files = [.. new DirectoryInfo(folder)
|
||||
.EnumerateFiles("*", SearchOption.TopDirectoryOnly)
|
||||
.OrderBy(f => f.LastAccessTimeUtc)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogWarning(ex, "Failed to enumerate files in {folder}", folder);
|
||||
FileCacheSize = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
var entries = new List<(FileInfo fi, long size)>(files.Count);
|
||||
long total = 0;
|
||||
var files = Directory.EnumerateFiles(_configService.Current.CacheFolder)
|
||||
.Select(f => new FileInfo(f))
|
||||
.OrderBy(f => f.LastAccessTime)
|
||||
.ToList();
|
||||
|
||||
long totalSize = 0;
|
||||
|
||||
foreach (var f in files)
|
||||
{
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
long size;
|
||||
if (_configService.Current.UseCompactor)
|
||||
try
|
||||
{
|
||||
try
|
||||
long size = 0;
|
||||
|
||||
if (!isWine)
|
||||
{
|
||||
size = _fileCompactor.GetFileSizeOnDisk(f);
|
||||
if (size < 0) size = f.Length;
|
||||
try
|
||||
{
|
||||
size = _fileCompactor.GetFileSizeOnDisk(f);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogTrace(ex, "GetFileSizeOnDisk failed for {file}, using fallback length", f.FullName);
|
||||
size = f.Length;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
else
|
||||
{
|
||||
Logger.LogTrace(ex, "GetFileSizeOnDisk failed for {file}, using Length", f.FullName);
|
||||
size = f.Length;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size = f.Length;
|
||||
|
||||
totalSize += size;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogTrace(ex, "Error getting size for {file}", f.FullName);
|
||||
}
|
||||
|
||||
|
||||
entries.Add((f, size));
|
||||
total += size;
|
||||
}
|
||||
|
||||
FileCacheSize = total;
|
||||
FileCacheSize = totalSize;
|
||||
|
||||
if (Directory.Exists(_configService.Current.CacheFolder + "/downscaled"))
|
||||
{
|
||||
@@ -488,7 +484,7 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
||||
{
|
||||
long size = 0;
|
||||
|
||||
if (!_dalamudUtil.IsWine)
|
||||
if (!isWine)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -514,38 +510,34 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
||||
}
|
||||
|
||||
FileCacheSize = (totalSize + totalSizeDownscaled);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FileCacheSize = totalSize;
|
||||
}
|
||||
|
||||
var maxCacheInBytes = (long)(_configService.Current.MaxLocalCacheInGiB * 1024d * 1024d * 1024d);
|
||||
var maxCacheInBytes = (long)(_configService.Current.MaxLocalCacheInGiB * 1024d * 1024d * 1024d);
|
||||
if (FileCacheSize < maxCacheInBytes)
|
||||
return;
|
||||
|
||||
var buffer = (long)(maxCacheBytes * 0.05d);
|
||||
var target = maxCacheBytes - buffer;
|
||||
var maxCacheBuffer = maxCacheInBytes * 0.05d;
|
||||
|
||||
var i = 0;
|
||||
while (i < entries.Count && FileCacheSize > target)
|
||||
while (FileCacheSize > maxCacheInBytes - (long)maxCacheBuffer && files.Count > 0)
|
||||
{
|
||||
token.ThrowIfCancellationRequested();
|
||||
var oldestFile = files[0];
|
||||
|
||||
var (fi, sz) = entries[i];
|
||||
try
|
||||
{
|
||||
File.Delete(fi.FullName);
|
||||
FileCacheSize -= sz;
|
||||
long fileSize = oldestFile.Length;
|
||||
File.Delete(oldestFile.FullName);
|
||||
FileCacheSize -= fileSize;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogTrace(ex, "Failed to delete old file {file}", fi.FullName);
|
||||
}
|
||||
finally
|
||||
{
|
||||
i++;
|
||||
Logger.LogTrace(ex, "Failed to delete old file {file}", oldestFile.FullName);
|
||||
}
|
||||
|
||||
files.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0-windows</TargetFramework>
|
||||
<TargetFramework>net9.0-windows7.0</TargetFramework>
|
||||
<Platforms>x64</Platforms>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using LightlessSync.API.Dto.Group;
|
||||
using LightlessSync.PlayerData.Factories;
|
||||
using LightlessSync.PlayerData.Pairs;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": 1,
|
||||
"dependencies": {
|
||||
"net10.0-windows7.0": {
|
||||
"net9.0-windows7.0": {
|
||||
"Blake3": {
|
||||
"type": "Direct",
|
||||
"requested": "[2.0.0, )",
|
||||
@@ -191,7 +191,8 @@
|
||||
"dependencies": {
|
||||
"Microsoft.AspNetCore.Http.Connections.Common": "9.0.3",
|
||||
"Microsoft.Extensions.Logging.Abstractions": "9.0.3",
|
||||
"Microsoft.Extensions.Options": "9.0.3"
|
||||
"Microsoft.Extensions.Options": "9.0.3",
|
||||
"System.Net.ServerSentEvents": "9.0.3"
|
||||
}
|
||||
},
|
||||
"Microsoft.AspNetCore.Http.Connections.Common": {
|
||||
@@ -210,7 +211,8 @@
|
||||
"Microsoft.AspNetCore.SignalR.Common": "9.0.3",
|
||||
"Microsoft.AspNetCore.SignalR.Protocols.Json": "9.0.3",
|
||||
"Microsoft.Extensions.DependencyInjection": "9.0.3",
|
||||
"Microsoft.Extensions.Logging": "9.0.3"
|
||||
"Microsoft.Extensions.Logging": "9.0.3",
|
||||
"System.Threading.Channels": "9.0.3"
|
||||
}
|
||||
},
|
||||
"Microsoft.AspNetCore.SignalR.Common": {
|
||||
|
||||
Reference in New Issue
Block a user