diff --git a/src/MonkeyCache.LiteDB/Barrel.cs b/src/MonkeyCache.LiteDB/Barrel.cs index 0fea3cd..a18b46f 100644 --- a/src/MonkeyCache.LiteDB/Barrel.cs +++ b/src/MonkeyCache.LiteDB/Barrel.cs @@ -33,8 +33,15 @@ public class Barrel : IBarrel /// public static IBarrel Current => (instance ?? (instance = new Barrel())); - public static IBarrel Create(string cacheDirectory) - => new Barrel(cacheDirectory); + public static IBarrel Create(string cacheDirectory, bool cache = false) + { + if (!cache) + return new Barrel(cacheDirectory); + + if(instance == null) + instance = new Barrel(cacheDirectory); + return instance; + } readonly JsonSerializerSettings jsonSettings; Barrel(string cacheDirectory = null) @@ -259,14 +266,17 @@ public void Add(string key, T data, TimeSpan expireIn, string eTag = null, Js Add(key, dataJson, expireIn, eTag); } -#endregion + #endregion -#region Empty Methods + #region Empty Methods /// /// Empties all expired entries that are in the Barrel. /// Throws an exception if any deletions fail and rolls back changes. /// - public void EmptyExpired() => col.DeleteMany(b => b.ExpirationDate.ToUniversalTime() < DateTime.UtcNow); + public void EmptyExpired() + { + col.DeleteMany(b => b.ExpirationDate < DateTime.UtcNow); + } /// /// Empties all expired entries that are in the Barrel. diff --git a/src/MonkeyCache.TestsLiteDB/BarrelTests.cs b/src/MonkeyCache.TestsLiteDB/BarrelTests.cs index e81995e..187b2f8 100644 --- a/src/MonkeyCache.TestsLiteDB/BarrelTests.cs +++ b/src/MonkeyCache.TestsLiteDB/BarrelTests.cs @@ -18,7 +18,7 @@ public partial class CustomDirBarrelTests public override void SetupBarrel() { var dir = BarrelUtils.GetBasePath("com.refractored.monkeylite.customdir"); - this.barrel = Barrel.Create(dir); + this.barrel = Barrel.Create(dir, true); } } diff --git a/src/MonkeyCache.TestsShared/BarrelTests.cs b/src/MonkeyCache.TestsShared/BarrelTests.cs index 46a8ab8..c01df26 100644 --- a/src/MonkeyCache.TestsShared/BarrelTests.cs +++ b/src/MonkeyCache.TestsShared/BarrelTests.cs @@ -11,7 +11,8 @@ namespace MonkeyCache.Tests { [TestClass] - public partial class BarrelTests + [DoNotParallelize()] + public partial class BarrelTests { IEnumerable monkeys; @@ -527,6 +528,7 @@ void PerformanceTestRunner (int threads, bool allowDuplicateKeys, int keysPerThr } [TestClass] + [DoNotParallelize()] public partial class CustomDirBarrelTests : BarrelTests { }