Esempio n. 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));
        }
Esempio n. 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 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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
0
        public void NoHashCode_CacheHit_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, () => InvokeCacheMiss(expected));

            Assert.AreEqual(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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
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));
        }
Esempio n. 10
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));
        }