示例#1
0
        public ActionResult Index()
        {
            var sw = new Stopwatch();
            sw.Start();

            //create the ketchup client
            var bucket = new KetchupClient("localhost",11211).DefaultBucket;
            var keylist = "gowns-sync";

            //check to see if the list of ids is in the cache:

            var ids = bucket.Get(keylist) as List<int>;
            if(ids == null)
            {
                ids = GalleryImage.QueryList();
                var success = bucket.Set(keylist, ids);
                if(!success) Response.Write("Failed to Write Cache Key " + keylist);
            }

            //create the model
            var galleryImages = new List<GalleryImage>();
            foreach(var id in ids)
            {
                var key = keylist + "-" + id;

                var galleryImage = bucket.Get(key) as GalleryImage;
                if(galleryImage == null)
                {
                    galleryImage = GalleryImage.QueryOne(id);
                    var success = bucket.Set(key, galleryImage);
                    if(!success) Response.Write("Failed to Write Cache Key " + key);
                }

                //process the data after retrieving it from the DB or cache
                galleryImage.ImageData = galleryImage.ProcessDataFor20ms();

                //add it to the model collection
                galleryImages.Add(galleryImage);

                //why do we add it to the model collection after instead of just caching processed data and the whole collection?
                //1. limits in memcached size, not as big a deal anymore
                //2. may want to use this cache object later, could still cache both
                //3. not as cool for my asynchronous demo.
            }

            sw.Stop();
            ViewData["Time"] = sw.ElapsedMilliseconds;
            bucket.Flush();
            return View("Grid", galleryImages);
        }
示例#2
0
        public static void Main(string[] args)
        {
            var bucket = new KetchupClient("localhost", 11211).DefaultBucket;
            var key = "key-default";
            var value = "key-default-value";

            //Set
            bucket.Set(key, value);

            //Get
            var expected = value;
            var actual = bucket.Get<string>(key);

            //Delete
            bucket.Delete(key);

            Console.WriteLine("Expected: " + expected + " Actual: " + actual + " Match: " + (expected == actual).ToString());
            Finish();
        }
示例#3
0
        public static void Main(string[] args)
        {
            var bucket = new KetchupClient("localhost", 11211).DefaultBucket;
            var key = "key-silent";
            var value = "key-silent-value";
            var state = default(object);

            //Silent set never returns
            bucket.Set(key, value);

            //Silent Get only returns on hit
            bucket.Get<string>(key,
                (val, stateGetHit) =>
                {
                    Console.WriteLine("Get command for key " + key + " returned value " + value);
                    //Silent delete never returns
                    bucket.Delete(key);
                    Finish();
                },
                state
            );
        }
示例#4
0
 public void GivenANewKetchupClient()
 {
     ketchup = new KetchupClient();
 }
示例#5
0
        private static void Run()
        {
            Console.WriteLine("Enter the number of operations or enter to quit");
            var numberOfOperations = 0;
            if (!int.TryParse(Console.ReadLine(), out numberOfOperations)) return;

            var ecli = new MemcachedClient();
            var kcli = new KetchupClient();
            var bucket = kcli.GetBucket("default");
            var etime = 0d;

            Console.WriteLine("Number of Operations: " + numberOfOperations);
            if (!debugAsync)
            {
                etime = SetAndGetEnyim(numberOfOperations, ecli);
                Console.WriteLine("Enyim: " + etime + " seconds");
                var ktimes = SetAndGetKetchupSync(numberOfOperations, bucket);
                var ptimes = Math.Round(((etime - ktimes) / etime) * 100);
                Console.WriteLine("Ketchup Sync: " + ktimes + " seconds (" + ptimes + "% faster)");
            }

            var ktimea = SetAndGetKetchupAsync(numberOfOperations, bucket);
            if (!debugAsync)
            {
                var ptimea = Math.Round(((etime - ktimea) / etime) * 100);
                Console.WriteLine("Ketchup Async: " + ktimea + " seconds (" + ptimea + "% faster)");
            }

            Run();
        }
示例#6
0
        internal KetchupConfig Init(KetchupClient client)
        {
            foreach (var bucket in buckets.Values)
            {
                bucket.Client = client;

                /* there are 3 options for buckets: nodes defined, port defined, all endpoints
                 * there are 2 options for nodes: ip defined, ip+port defined
                 */

                //first add it to the bucket hash and initialize the nodelist
                bucketNodes.Add(bucket.Name, new List<Node>());

                //option 1: nodes are defined, if port is defined, use port, otherwise use default port
                if (bucket.ConfigNodes.Count > 0)
                {
                    InitSpecifiedNodes(bucket);
                    continue;
                }

                //option 2: port is defined in the bucket list, use port with ips in node list
                if (bucket.Port > 0)
                {
                    InitPortNodes(bucket, configNodes);
                    continue;
                }

                InitAllNodes(bucket, configNodes);
            }

            Current = this;
            return this;
        }
示例#7
0
 public static KetchupConfig Init(KetchupConfig config, KetchupClient client)
 {
     config.Init(client);
     return config;
 }