protected void BenchmarkWork(ISyncCacheLayer cacheLayer)
        {
            for (var iterationCount = 0; iterationCount < WorkIterations; iterationCount++)
            {
                //Get 100 misses
                for (var i = 0; i < 100; i++)
                {
                    cacheLayer.Get <int>("GetMiss_" + i);
                }

                var startDate = DateTime.UtcNow.AddDays(-50);

                //Set first 100 (simple type)
                for (var i = 0; i < 100; i++)
                {
                    cacheLayer.Set("Comparison_" + i, new CacheEntry <int>(1, startDate.AddDays(i) + TimeSpan.FromDays(1)));
                }
                //Set last 100 (complex type)
                for (var i = 100; i < 200; i++)
                {
                    cacheLayer.Set("Comparison_" + i, new CacheEntry <ComplexType>(new ComplexType
                    {
                        ExampleString       = "Hello World",
                        ExampleNumber       = 42,
                        ExampleDate         = new DateTime(2000, 1, 1),
                        DictionaryOfNumbers = new Dictionary <string, int>()
                        {
                            { "A", 1 }, { "B", 2 }, { "C", 3 }
                        }
                    }, startDate.AddDays(i - 100) + TimeSpan.FromDays(1)));
                }

                //Get first 50 (simple type)
                for (var i = 0; i < 50; i++)
                {
                    cacheLayer.Get <int>("Comparison_" + i);
                }
                //Get last 50 (complex type)
                for (var i = 150; i < 200; i++)
                {
                    cacheLayer.Get <ComplexType>("Comparison_" + i);
                }

                //Evict middle 100
                for (var i = 50; i < 150; i++)
                {
                    cacheLayer.Evict("Comparison_" + i);
                }

                //Cleanup outer 100
                cacheLayer.Cleanup();
            }
        }
Esempio n. 2
0
        protected static void AssertCacheCleanup(ISyncCacheLayer cacheLayer)
        {
            CacheEntry <int> DoCleanupTest(DateTime dateTime)
            {
                var cacheKey = $"AssertCacheCleanup-(DateTime:{dateTime})";

                var cacheEntry = new CacheEntry <int>(98, dateTime);

                cacheLayer.Set(cacheKey, cacheEntry);

                cacheLayer.Cleanup();

                return(cacheLayer.Get <int>(cacheKey));
            }

            Assert.IsNotNull(DoCleanupTest(DateTime.UtcNow.AddDays(1)), "Cleanup removed entry that was still live");
            Assert.IsNull(DoCleanupTest(DateTime.UtcNow.AddDays(-1)), "Cleanup kept entry past the end of life");
        }