diff --git a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/BTree.cs b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/BTree.cs index 1b17e0c124..614354100a 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/DataSource/BTree.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/DataSource/BTree.cs @@ -1,4 +1,5 @@ -using CSharpTest.Net.Collections; +using System.Configuration; +using CSharpTest.Net.Collections; using CSharpTest.Net.Serialization; namespace Umbraco.Web.PublishedCache.NuCache.DataSource @@ -14,6 +15,12 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource CreateFile = exists ? CreatePolicy.IfNeeded : CreatePolicy.Always, FileName = filepath, + // read or write but do NOT keep in memory + CachePolicy = CachePolicy.None, + + // default is 4096, min 2^9 = 512, max 2^16 = 64K + FileBlockSize = GetBlockSize(), + // other options? }; @@ -25,6 +32,28 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource return tree; } + private static int GetBlockSize() + { + var blockSize = 4096; + + var appSetting = ConfigurationManager.AppSettings["Umbraco.Web.PublishedCache.NuCache.BTree.BlockSize"]; + if (appSetting == null) + return blockSize; + + if (!int.TryParse(appSetting, out blockSize)) + throw new ConfigurationErrorsException($"Invalid block size value \"{appSetting}\": not a number."); + + var bit = 0; + for (var i = blockSize; i != 1; i >>= 1) + bit++; + if (1 << bit != blockSize) + throw new ConfigurationErrorsException($"Invalid block size value \"{blockSize}\": must be a power of two."); + if (blockSize < 512 || blockSize > 65536) + throw new ConfigurationErrorsException($"Invalid block size value \"{blockSize}\": must be >= 512 and <= 65536."); + + return blockSize; + } + /* class ListOfIntSerializer : ISerializer> {