/// <summary>Limits the size of the working set for the file system cache.</summary>
/// <param name="MinimumFileCacheSize">The minimum size of the file cache, in bytes. To flush, use UInt64.MaxValue.</param>
/// <param name="MaximumFileCacheSize">The maximum size of the file cache, in bytes. Must be > min + 64KB</param>
/// <param name="Flags">See File_Cache_Flags</param>
/// <returns>0=fail !0=success</returns>
[DllImport("kernel32.dll", SetLastError=true)]
static extern Int32 SetSystemFileCacheSize(IntPtr MinimumFileCacheSize, IntPtr MaximumFileCacheSize, File_Cache_Flags Flags);
Declare Function SetSystemFileCacheSize Lib "kernel32.dll" (TODO) As TODO
/// <summary>Flags for use with SetSystemFileCacheSize. Note that corresponding enable & disable are mutually exclusive and will fail.</summary>
[Flags]
public enum File_Cache_Flags : uint
{
MAX_HARD_ENABLE = 0x00000001,
MAX_HARD_DISABLE = 0x00000002,
MIN_HARD_ENABLE = 0x00000004,
MIN_HARD_DISABLE = 0x00000008,
}
None.
Please add some!
/// <summary>Sets or unsets File Cache Size</summary>
/// <param name="MinimumFileCacheSize">Minimum Size, or zero for disable minimum</param>
/// <param name="MaximumFileCacheSize">Maximum Size, or zero for disable maximum</param>
public static void SetSystemFileCacheSize(ulong MinimumFileCacheSize, ulong MaximumFileCacheSize)
{
if (Environment.OSVersion.Version.Major < 5 || (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor < 2))
throw new NotImplementedException("Windows 5.2 (XP 64/2003 and up) is required for File System Cache Control");
if (IntPtr.Size == 4 && MinimumFileCacheSize > UInt32.MaxValue)
throw new InvalidOperationException("Minimum Size is Invalid - SetSystemFileCacheSize");
if (IntPtr.Size == 4 && MaximumFileCacheSize > UInt32.MaxValue)
MaximumFileCacheSize = UInt32.MaxValue;
File_Cache_Flags
flags = (File_Cache_Flags)0;
if (MinimumFileCacheSize > 0)
flags |= File_Cache_Flags.MIN_HARD_ENABLE;
else
flags |= File_Cache_Flags.MIN_HARD_DISABLE;
if (MaximumFileCacheSize > 0 && MaximumFileCacheSize>MinimumFileCacheSize + 64 * 1024) // min must be <64K lower
flags |= File_Cache_Flags.MAX_HARD_ENABLE;
else
flags |= File_Cache_Flags.MAX_HARD_DISABLE;
int
result = 0;
if(IntPtr.Size!=4)
result = SetSystemFileCacheSize(new IntPtr((long)MinimumFileCacheSize), new IntPtr((long)MaximumFileCacheSize), flags);
else
result = SetSystemFileCacheSize(new IntPtr((int)MinimumFileCacheSize), new IntPtr((int)MaximumFileCacheSize), flags);
if (result == 0)
throw new Win32Exception();
}