diff --git a/src/MonkeyCache.FileStore/Barrel.cs b/src/MonkeyCache.FileStore/Barrel.cs index f65313d..f56d755 100644 --- a/src/MonkeyCache.FileStore/Barrel.cs +++ b/src/MonkeyCache.FileStore/Barrel.cs @@ -16,6 +16,7 @@ public class Barrel : IBarrel ReaderWriterLockSlim indexLocker; Lazy baseDirectory; HashAlgorithm hashAlgorithm; + object locker = new object(); /// /// FileStore Barrel constructor @@ -32,8 +33,6 @@ public class Barrel : IBarrel }); hashAlgorithm = hash; - if (hashAlgorithm == null) - hashAlgorithm = MD5.Create(); indexLocker = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); @@ -469,7 +468,18 @@ void LoadIndex() string Hash(string input) { - var data = hashAlgorithm.ComputeHash(Encoding.Default.GetBytes(input)); + byte[] data; + if(hashAlgorithm is null) + { + data = MD5.HashData(Encoding.Default.GetBytes(input)); + } + else + { + lock(locker) + { + data = hashAlgorithm.ComputeHash(Encoding.Default.GetBytes(input)); + } + } return BitConverter.ToString(data); }