Enable configuration of NuCache BTree block size
This commit is contained in:
@@ -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<List<int>>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user