private int GetDefaultMemoryCacheLimitMegabytes()
{
var cacheSizeMaxSetting = new IntegerSetting(settings["Raven/Esent/CacheSizeMax"], 1024);
// we need to leave ( a lot ) of room for other things as well, so we min the cache size
var val = (MemoryStatistics.TotalPhysicalMemory/2) -
// reduce the unmanaged cache size from the default min
cacheSizeMaxSetting.Value;
if (val < 0)
return 128; // if machine has less than 1024 MB, then only use 128 MB
return val;
}