Beispiel #1
0
        static void CacheTest()
        {
            var cache = new NGinnBPM.MessageBus.Impl.SimpleCache <string, string>()
            {
            };

            cache.MaxCapacity = 100;
            for (int i = 0; i < 150; i++)
            {
                var g = cache.Get(i.ToString(), x => "abc_" + i);
            }
            for (int i = 150; i > 0; i--)
            {
                var g = cache.Get(i.ToString(), x => "def_" + i);
            }

            Console.WriteLine("Hits: {0}", cache.HitRatio);

            for (int i = 150; i > 0; i--)
            {
                var g = cache.Get((i % 10).ToString(), x => "def_" + i % 10);
            }

            Console.WriteLine("Hits: {0}", cache.HitRatio);

            cache = new SimpleCache <string, string> {
                MaxCapacity = 10
            };
            for (int i = 0; i < 100; i++)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object v)
                {
                    var r = cache.Get(v.ToString(), delegate(string t)
                    {
                        log.Info("Getting v for {0}", t);
                        Thread.Sleep(1000);
                        log.Info("Got v for {0}", t);
                        return("abc_" + t);
                    });
                }), i % 10);
            }
            Console.ReadLine();
            Console.WriteLine("Hits: {0}", cache.HitRatio);
        }
        static void CacheTest()
        {
            var cache = new NGinnBPM.MessageBus.Impl.SimpleCache<string, string>() {  };
            cache.MaxCapacity = 100;
            for (int i = 0; i < 150; i++)
            {
                var g = cache.Get(i.ToString(), x => "abc_" + i);
            }
            for (int i = 150; i > 0; i--)
            {
                var g = cache.Get(i.ToString(), x => "def_" + i);
            }

            Console.WriteLine("Hits: {0}", cache.HitRatio);

            for (int i = 150; i > 0; i--)
            {
                var g = cache.Get((i % 10).ToString(), x => "def_" + i % 10);
            }

            Console.WriteLine("Hits: {0}", cache.HitRatio);

            cache = new SimpleCache<string, string> { MaxCapacity = 10 };
            for (int i = 0; i < 100; i++)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object v)
                {
                    var r = cache.Get(v.ToString(), delegate(string t)
                    {
                        log.Info("Getting v for {0}", t);
                        Thread.Sleep(1000);
                        log.Info("Got v for {0}", t);
                        return "abc_" + t;
                    });
                }), i % 10);

            }
            Console.ReadLine();
            Console.WriteLine("Hits: {0}", cache.HitRatio);
        }