From fcf95f047bf1a0f0c87c061c75746fd9c5d21916 Mon Sep 17 00:00:00 2001 From: rvazarkar Date: Mon, 31 Jul 2023 14:25:43 -0400 Subject: [PATCH] chore: remove invalidation function, offload to consumer --- src/CommonLib/Cache.cs | 16 ---------------- test/unit/CacheTest.cs | 26 -------------------------- 2 files changed, 42 deletions(-) diff --git a/src/CommonLib/Cache.cs b/src/CommonLib/Cache.cs index deaa23ea..4f1fd57b 100644 --- a/src/CommonLib/Cache.cs +++ b/src/CommonLib/Cache.cs @@ -166,22 +166,6 @@ public static void SetCacheInstance(Cache cache) CreateMissingDictionaries(); } - public static bool CacheNeedsInvalidation(Cache cache, Version version) - { - var threshold = DateTime.Now.Subtract(TimeSpan.FromDays(30)); - if (cache.CacheCreationDate < threshold) - { - return true; - } - - if (cache.CacheCreationVersion == null || version > cache.CacheCreationVersion) - { - return true; - } - - return false; - } - /// /// Gets stats from the currently loaded cache /// diff --git a/test/unit/CacheTest.cs b/test/unit/CacheTest.cs index 87e2f0be..a4d04037 100644 --- a/test/unit/CacheTest.cs +++ b/test/unit/CacheTest.cs @@ -13,23 +13,6 @@ public CacheTest(ITestOutputHelper testOutputHelper) { _testOutputHelper = testOutputHelper; } - - [Fact] - public void Cache_TestCacheInvalidation() - { - var cache = Cache.CreateNewCache(); - var version = new Version(1, 0, 0); - cache.CacheCreationVersion = version; - - Assert.True(Cache.CacheNeedsInvalidation(cache, new Version(1,0,1))); - Assert.False(Cache.CacheNeedsInvalidation(cache, new Version(1,0,0))); - - var time = DateTime.Now.Subtract(TimeSpan.FromDays(29)); - cache.CacheCreationDate = time; - Assert.False(Cache.CacheNeedsInvalidation(cache, version)); - cache.CacheCreationDate = DateTime.Now.Subtract(TimeSpan.FromDays(31)); - Assert.True(Cache.CacheNeedsInvalidation(cache, version)); - } [Fact] public void Cache_TestNewCache() @@ -42,14 +25,5 @@ public void Cache_TestNewCache() Assert.Equal(cache.CacheCreationVersion, version); Assert.Equal(cache.CacheCreationDate, time); } - - [Fact] - public void Cache_OldCacheWillInvalidate() - { - const string json = "{\"GlobalCatalogCache\": {}, \"IdToTypeCache\": {}, \"MachineSidCache\": {}, \"SIDToDomainCache\": {}, \"ValueToIdCache\": {}}"; - var cache = JsonConvert.DeserializeObject(json); - Assert.Null(cache.CacheCreationVersion); - Assert.True(Cache.CacheNeedsInvalidation(cache, new Version(1,0,0))); - } } }