You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
3.0 KiB
78 lines
3.0 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AIK.Models.FileModels
|
|
{
|
|
public class FileCacheStats
|
|
{
|
|
public int TotalCachedFiles { get; set; }
|
|
public long TotalCacheSizeBytes { get; set; }
|
|
public string TotalCacheSizeFormatted => FormatFileSize(TotalCacheSizeBytes);
|
|
public int ExpiredFilesCount { get; set; }
|
|
public string CacheDirectory { get; set; }
|
|
public DateTime LastCleanupTime { get; set; }
|
|
public long AvailableDiskSpaceBytes { get; set; }
|
|
public string AvailableDiskSpaceFormatted => FormatFileSize(AvailableDiskSpaceBytes);
|
|
public Dictionary<string, int> FileTypeCounts { get; set; } = new Dictionary<string, int>();
|
|
|
|
private static string FormatFileSize(long bytes)
|
|
{
|
|
string[] sizes = { "B", "KB", "MB", "GB" };
|
|
int order = 0;
|
|
double len = bytes;
|
|
while (len >= 1024 && order < sizes.Length - 1)
|
|
{
|
|
order++;
|
|
len /= 1024;
|
|
}
|
|
return $"{len:0.##} {sizes[order]}";
|
|
}
|
|
}
|
|
public class CachedFileInfo
|
|
{
|
|
public string FileUrl { get; set; }
|
|
public string CacheKey { get; set; }
|
|
public string LocalFilePath { get; set; }
|
|
public string FileName { get; set; }
|
|
public string FileExtension { get; set; }
|
|
public string MimeType { get; set; }
|
|
public long FileSizeBytes { get; set; }
|
|
public string FileSizeFormatted => FormatFileSize(FileSizeBytes);
|
|
public DateTime CreatedTime { get; set; }
|
|
public DateTime LastAccessTime { get; set; }
|
|
public int AccessCount { get; set; }
|
|
public DateTime ExpiryTime { get; set; }
|
|
public bool IsExpired => ExpiryTime < DateTime.Now;
|
|
public string FileHash { get; set; }
|
|
public TimeSpan DownloadTime { get; set; }
|
|
public bool IsValid { get; set; } = true;
|
|
|
|
private static string FormatFileSize(long bytes)
|
|
{
|
|
string[] sizes = { "B", "KB", "MB", "GB" };
|
|
int order = 0;
|
|
double len = bytes;
|
|
while (len >= 1024 && order < sizes.Length - 1)
|
|
{
|
|
order++;
|
|
len /= 1024;
|
|
}
|
|
return $"{len:0.##} {sizes[order]}";
|
|
}
|
|
}
|
|
public class FileCacheConfig
|
|
{
|
|
public TimeSpan DefaultCacheExpiry { get; set; } = TimeSpan.FromDays(30);
|
|
public long MaxCacheSizeBytes { get; set; } = 2L * 1024 * 1024 * 1024; // 2GB
|
|
public long MinFreeDiskSpaceBytes { get; set; } = 500L * 1024 * 1024; // 500MB
|
|
public int MaxRetryCount { get; set; } = 3;
|
|
public TimeSpan RetryDelay { get; set; } = TimeSpan.FromSeconds(2);
|
|
public TimeSpan HttpClientTimeout { get; set; } = TimeSpan.FromSeconds(60);
|
|
public string CacheDirectory { get; set; }
|
|
public bool EnableAutoCleanup { get; set; } = true;
|
|
public TimeSpan CleanupInterval { get; set; } = TimeSpan.FromHours(1);
|
|
}
|
|
}
|
|
|