Example #1
0
        public void TestMethod3()
        {
            var cachetastic = new Cachetastic
            {
                Lifetime = TimeSpan.FromSeconds(1)
            };
            var stopwatch = Stopwatch.StartNew();

            // Load the Cache with Garbage
            for (int i = 0; i < 1000000; i++)
            {
                int iTemp = i;
                cachetastic.Get(i.ToString(), () => iTemp);
            }

            Thread.Sleep(1000);

            for (int i = 0; i < 1000000; i++)
            {
                int iTemp = i;
                cachetastic.Get(i.ToString(), () => iTemp);
            }

            Debug.WriteLine(String.Format("Time to Load (ms): {0}", stopwatch.ElapsedMilliseconds));
        }
Example #2
0
        public void TestMethod3()
        {
            var cachetastic = new Cachetastic
            {
                Lifetime = TimeSpan.FromSeconds(1)
            };
            var stopwatch = Stopwatch.StartNew();

            // Load the Cache with Garbage
            for (int i = 0; i < 1000000; i++)
            {
                int iTemp = i;
                cachetastic.Get(i.ToString(), () => iTemp);
            }

            Thread.Sleep(1000);

            for (int i = 0; i < 1000000; i++)
            {
                int iTemp = i;
                cachetastic.Get(i.ToString(), () => iTemp);
            }

            Debug.WriteLine(String.Format("Time to Load (ms): {0}", stopwatch.ElapsedMilliseconds));
        }
        public void CacheShouldInvalidateAndUpdateAfterLifeTimeExpires()
        {
            var cachetastic = new Cachetastic { Lifetime = TimeSpan.FromMilliseconds(500) };
            DateTime originalDateTime = cachetastic.Get("id", () => DateTime.UtcNow);
            System.Threading.Thread.Sleep(1000);
            DateTime newDateTime = cachetastic.Get("id", () => DateTime.UtcNow);

            Assert.AreNotEqual(originalDateTime, newDateTime);
        }
        public void CacheMiss_ShouldInvokeFunc_ShouldReturnExpectedResult()
        {
            const string key = "Linda";
            const string hashcode = "Honey";
            const string expected = "Sweet";

            string actual = new Cachetastic().Get(key, hashcode, () => InvokeCacheHit(expected));

            Assert.AreEqual(expected, actual);
        }
Example #5
0
        public void NoHashCode_CacheMiss_ShouldInvokeFunc_ShouldReturnExpectedResult()
        {
            const string key      = "Linda";
            const string hashcode = "Honey";
            const string expected = "Sweet";

            string actual = new Cachetastic().Get(key, hashcode, () => InvokeCacheHit(expected));

            Assert.AreEqual(expected, actual);
        }
        public void CacheHit_WithDifferentHashcode_ShouldNotInvokeFunc_ShouldReturnCachedResult()
        {
            const string key = "Linda";
            const string hashcode = "Honey";
            const string expected = "Sweet";

            var cachetastic = new Cachetastic();
            cachetastic.Get(key, hashcode, () => InvokeCacheHit(expected));
            string actual = cachetastic.Get(key, hashcode + "x", () => InvokeCacheMiss(expected));

            Assert.AreNotEqual(expected, actual);
        }
Example #7
0
        public void CacheShouldInvalidateAndUpdateAfterLifeTimeExpires()
        {
            var cachetastic = new Cachetastic {
                Lifetime = TimeSpan.FromMilliseconds(500)
            };
            DateTime originalDateTime = cachetastic.Get("id", () => DateTime.UtcNow);

            System.Threading.Thread.Sleep(1000);
            DateTime newDateTime = cachetastic.Get("id", () => DateTime.UtcNow);

            Assert.AreNotEqual(originalDateTime, newDateTime);
        }
Example #8
0
        public void CacheHit_WithDifferentHashcode_ShouldNotInvokeFunc_ShouldReturnCachedResult()
        {
            const string key      = "Linda";
            const string hashcode = "Honey";
            const string expected = "Sweet";

            var cachetastic = new Cachetastic();

            cachetastic.Get(key, hashcode, () => InvokeCacheHit(expected));
            string actual = cachetastic.Get(key, hashcode + "x", () => InvokeCacheMiss(expected));

            Assert.AreNotEqual(expected, actual);
        }
        public void CacheShouldBeEmpty_After_LifetimeExpires()
        {
            var cachetastic = new Cachetastic();
            cachetastic.Lifetime = TimeSpan.FromMilliseconds(500);
            for (int i = 0; i < 10000; i++)
            {
                int iTemp = i;
                cachetastic.Get(i.ToString(), () => iTemp);
            }

            System.Threading.Thread.Sleep(1000);

            cachetastic.Get("1", () => 1);

            // We actually expect a result of 1 here, as we need to add an item after the Lifetime for the Pruning to take place.
            Assert.AreEqual(1, cachetastic.Count);
        }
Example #10
0
        public void CacheShouldBeEmpty_After_LifetimeExpires()
        {
            var cachetastic = new Cachetastic();

            cachetastic.Lifetime = TimeSpan.FromMilliseconds(500);
            for (int i = 0; i < 10000; i++)
            {
                int iTemp = i;
                cachetastic.Get(i.ToString(), () => iTemp);
            }

            System.Threading.Thread.Sleep(1000);

            cachetastic.Get("1", () => 1);

            // We actually expect a result of 1 here, as we need to add an item after the Lifetime for the Pruning to take place.
            Assert.AreEqual(1, cachetastic.Count);
        }
Example #11
0
        public void TestMethod2()
        {
            var cachetastic = new Cachetastic();
            var stopwatch   = Stopwatch.StartNew();

            // Load the Cache with Garbage
            for (int i = 0; i < 1000000; i++)
            {
                int iTemp = i;
                cachetastic.Get(i.ToString(), () => iTemp);
            }

            for (int i = 0; i < 1000000; i++)
            {
                int iTemp = i;
                cachetastic.Get(i.ToString(), () => iTemp);
            }

            Debug.WriteLine(String.Format("Time to Load (ms): {0}", stopwatch.ElapsedMilliseconds));
        }
Example #12
0
        public void TestMethod2()
        {
            var cachetastic = new Cachetastic();
            var stopwatch = Stopwatch.StartNew();

            // Load the Cache with Garbage
            for (int i = 0; i < 1000000; i++)
            {
                int iTemp = i;
                cachetastic.Get(i.ToString(), () => iTemp);
            }

            for (int i = 0; i < 1000000; i++)
            {
                int iTemp = i;
                cachetastic.Get(i.ToString(), () => iTemp);
            }

            Debug.WriteLine(String.Format("Time to Load (ms): {0}", stopwatch.ElapsedMilliseconds));
        }