Beispiel #1
0
        //RuntimeCaching
        public static void RuntimeCaching(int [] numForFibbonachi)
        {
            CachingProvider cp = new CachingProvider();

            for (int i = 0; i < numForFibbonachi.Length; i++)
            {
                Console.WriteLine("For item {0} Fibonacci sequence is:", numForFibbonachi[i]);
                var sequenceFromCache = cp.GetCachedItem <int>(numForFibbonachi[i].ToString());
                if (sequenceFromCache != null)
                {
                    Console.WriteLine("value from Cache");
                    WriteResult(sequenceFromCache);
                }
                else
                {
                    var sequence = GetFibonacciSequence(numForFibbonachi[i]);
                    cp.AddItemToCache(numForFibbonachi[i].ToString(), sequence);
                    WriteResult(sequence);
                }
            }
        }