Exemple #1
0
        public void AsyncCache_Lazy_Created()
        {
            var cache = new FutureCache <int, double>(n => Math.Pow(n, 2));

            for (int i = 0; i < TestCount; i++)
            {
                Assert.AreEqual(Math.Pow(i, 2), cache.GetValue(i));
            }
        }
        public void AsyncCache_Set_Directly_Task() {
            var cache = new FutureCache<int, double>(n => Math.Pow(n, 2));

            for(int i = 0; i < TestCount; i++) {
                var key = i;
                cache.SetValue(key, Task.Factory.StartNew(() => Math.Pow(key, 3)));
            }

            Thread.Sleep(1 * TestCount);

            for(int i = 0; i < TestCount; i++) {
                var key = i;
                Assert.AreEqual(Math.Pow(key, 3), cache[key], "key=" + key);
            }
        }
Exemple #3
0
        public void AsyncCache_Set_Directly_Task()
        {
            var cache = new FutureCache <int, double>(n => Math.Pow(n, 2));

            for (int i = 0; i < TestCount; i++)
            {
                var key = i;
                cache.SetValue(key, Task.Factory.StartNew(() => Math.Pow(key, 3)));
            }

            Thread.Sleep(1 * TestCount);

            for (int i = 0; i < TestCount; i++)
            {
                var key = i;
                Assert.AreEqual(Math.Pow(key, 3), cache[key], "key=" + key);
            }
        }
        public void AsyncCache_Lazy_Created() {
            var cache = new FutureCache<int, double>(n => Math.Pow(n, 2));

            for(int i = 0; i < TestCount; i++)
                Assert.AreEqual(Math.Pow(i, 2), cache.GetValue(i));
        }