diff --git a/src/MonkeyCache.FileStore/Barrel.cs b/src/MonkeyCache.FileStore/Barrel.cs index 2b2b9dd..881f1ad 100644 --- a/src/MonkeyCache.FileStore/Barrel.cs +++ b/src/MonkeyCache.FileStore/Barrel.cs @@ -14,8 +14,14 @@ public class Barrel : IBarrel ReaderWriterLockSlim indexLocker; readonly JsonSerializerSettings jsonSettings; Lazy baseDirectory; + HashAlgorithm hashAlgorithm; - Barrel(string cacheDirectory = null) + /// + /// FileStore Barrel constructor + /// + /// Optionally specify directory where cache will live + /// Optionally specify hash algorithm + Barrel(string cacheDirectory = null, HashAlgorithm hash = null) { baseDirectory = new Lazy(() => { @@ -24,6 +30,10 @@ public class Barrel : IBarrel : cacheDirectory; }); + hashAlgorithm = hash; + if (hashAlgorithm == null) + hashAlgorithm = MD5.Create(); + indexLocker = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); jsonSettings = new JsonSerializerSettings @@ -456,10 +466,9 @@ void LoadIndex() } } - static string Hash(string input) + string Hash(string input) { - var md5Hasher = MD5.Create(); - var data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input)); + var data = hashAlgorithm.ComputeHash(Encoding.Default.GetBytes(input)); return BitConverter.ToString(data); }