Example #1
0
        public void Test_LoopThroughExpiredCachedListWithLocalCopyAndNullCheck()
        {
            int numberOfItems = 10;

            Dictionary <int, string> records = GetDictionaryFromCache(TestCacheItem.slim_testitem_1, numberOfItems);

            string value;
            int    half = numberOfItems / 2;


            SlimCacheManager.PurgeCacheItem(TestCacheItem.slim_testitem_1.ToString());
            records = GetDictionaryFromCache(TestCacheItem.slim_testitem_1, numberOfItems);
            Trace.WriteLine("\n\nStart Loop through local copy");
            foreach (int key in records.Keys)
            {
                if (half == key)
                {
                    Trace.WriteLine("Remove object from cache");
                    SlimCacheManager.PurgeCacheItem(TestCacheItem.slim_testitem_1.ToString());
                    Assert.AreEqual(false, SlimCacheManager.IsObjectCached(TestCacheItem.slim_testitem_1.ToString()));

                    Trace.WriteLine("Insert object into cache with half amount of items");
                    records = GetDictionaryFromCache(TestCacheItem.slim_testitem_1, half);
                    DebugUtility.GetDebugString(records);
                }

                if (records.ContainsKey(key))
                {
                    value = records[key];
                    Trace.WriteLine("Successfully retrieved value: " + value);
                }
            }
        }
Example #2
0
        public void Test_LoopThroughExpiredCachedListWithReinsertedValues()
        {
            int    numberOfItems = 10;
            string value;
            int    half = numberOfItems / 2;

            SlimCacheManager.PurgeCacheItem(TestCacheItem.slim_testitem_1.ToString());
            Trace.WriteLine("\n\nStart Loop through direct access with change");
            foreach (int key in GetDictionaryFromCache(TestCacheItem.slim_testitem_1, numberOfItems).Keys)
            {
                if (half == key)
                {
                    Trace.WriteLine("Remove object from cache");
                    SlimCacheManager.PurgeCacheItem(TestCacheItem.slim_testitem_1.ToString());
                    Assert.AreEqual(false, SlimCacheManager.IsObjectCached(TestCacheItem.slim_testitem_1.ToString()));

                    Trace.WriteLine("Insert object into cache with half amount of items");
                    var records = GetDictionaryFromCache(TestCacheItem.slim_testitem_1, half);
                    DebugUtility.GetDebugString(records);
                }

                if (key >= half)
                {
                    Assert.Throws <KeyNotFoundException>(delegate { value = GetDictionaryFromCache(TestCacheItem.slim_testitem_1, numberOfItems)[key]; });
                }
                else
                {
                    value = GetDictionaryFromCache(TestCacheItem.slim_testitem_1, numberOfItems)[key];
                    Trace.WriteLine("Successfully retrieved value: " + value);
                }
            }
        }
Example #3
0
        private Dictionary <int, string> GetDictionaryFromCache(TestCacheItem testCacheItem, int numberOfItems)
        {
            Trace.WriteLine("Method call: GetDictionaryFromCache(TestCacheItem, int)");

            return(SlimCacheManager.LoadFromCache <Dictionary <int, string> >(
                       testCacheItem.ToString()
                       , delegate { return GetHugeDictionary(numberOfItems); }));
        }
Example #4
0
 private SimpleObject GetCacheItem(int index)
 {
     return(SlimCacheManager.LoadFromCache <SimpleObject>(
                "TestItem"
                , delegate
     {
         Trace.WriteLine("DELEGATE CALL TO: ___START___  GetCacheItem, INDEX: " + index);
         Thread.Sleep(200);
         Trace.WriteLine("DELEGATE CALL TO: ___FINISH___  GetCacheItem, INDEX: " + index);
         return new SimpleObject()
         {
             MyString = "________" + index + "_________________________________________________ " + DateTime.UtcNow.ToString("HH:mm:ss.fff"),
             MyValue = index
         };
     }));
 }
Example #5
0
 private SimpleObject GetCacheItem2()
 {
     Trace.WriteLine("*************** GetCacheItem2 call at: " + DateTime.UtcNow.ToString("HH:mm:ss.fff") + " ******************");
     return(SlimCacheManager.LoadFromCache <SimpleObject>(
                "TestItem2"
                , delegate
     {
         Trace.WriteLine("DELEGATE CALL TO: ___FINISH___  GetCacheItem2");
         return new SimpleObject()
         {
             MyString = "_________________________________________________________ " + DateTime.UtcNow.ToString("HH:mm:ss.fff")
             ,
             MyValue = 0
         };
     }));
 }
Example #6
0
        public void Test_LoopThroughExpiredCachedList()
        {
            int    numberOfItems = 10;
            string value;
            int    half = numberOfItems / 2;

            SlimCacheManager.PurgeCacheItem(TestCacheItem.slim_testitem_1.ToString());
            Trace.WriteLine("\n\nStart Loop through direct access");
            foreach (int key in GetDictionaryFromCache(TestCacheItem.slim_testitem_1, numberOfItems).Keys)
            {
                value = GetDictionaryFromCache(TestCacheItem.slim_testitem_1, numberOfItems)[key];
                Trace.WriteLine("Successfully retrieved value: " + value);

                if (half == key)
                {
                    Trace.WriteLine("Remove object from cache");
                    SlimCacheManager.PurgeCacheItem(TestCacheItem.slim_testitem_1.ToString());
                    Assert.AreEqual(false, SlimCacheManager.IsObjectCached(TestCacheItem.slim_testitem_1.ToString()));
                }
            }
        }
Example #7
0
        public void Test_LoopThroughExpiredCachedListWithLocalCopy()
        {
            int numberOfItems = 10;

            Dictionary <int, string> records = GetDictionaryFromCache(TestCacheItem.slim_testitem_1, numberOfItems);

            string value;
            int    half = numberOfItems / 2;

            Trace.WriteLine("Start Loop through local copy");
            foreach (int key in records.Keys)
            {
                value = records[key];
                Trace.WriteLine("Successfully retrieved value: " + value);

                if (half == key)
                {
                    Trace.WriteLine("Remove object from cache");
                    SlimCacheManager.PurgeCacheItem(TestCacheItem.slim_testitem_1.ToString());
                    Assert.AreEqual(false, SlimCacheManager.IsObjectCached(TestCacheItem.slim_testitem_1.ToString()));
                }
            }
        }