// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using System.Collections.Generic; using System.Threading; using Infinispan.HotRod; using Infinispan.HotRod.Config; using Infinispan.HotRod.Event; namespace Cache.Infinispan.Functional { ////public class MyListener : ClientListener ////{ //// public MyListener() //// { //// AddListener((ClientCacheEntryCreatedEvent e) => { Console.WriteLine("Add : %s", e.GetKey()); }); //// AddListener((ClientCacheEntryRemovedEvent e) => { Console.WriteLine("Remove : %s\n", e.GetKey()); }); //// } ////} public class Program { private static void Test(IRemoteCache cache) { // basic put, get and remove cache.Put("v", 123); Console.WriteLine(cache.Get("v")); cache.Remove("v"); Console.WriteLine(cache.Get("v")); cache.Put("v", 123); Console.WriteLine(cache.Get("v")); // persistence int? counter = cache.Get("counter"); if (counter == null) { counter = 0; } counter++; Console.WriteLine(counter); cache.Put("counter", counter); // list all foreach (string key in cache.KeySet()) { Console.WriteLine("{0} = {1}", key, cache.Get(key)); } // listener does not work in 8.2.0 RC2 ////cache.AddClientListener(new MyListener(), new string[0], new string[0], null); ////cache.Put("x", 123); ////cache.Remove("x"); ////Thread.Sleep(10); // ensure sufficient time to call listener } public static void Main(string[] args) { ConfigurationBuilder b = new ConfigurationBuilder(); b.AddServer().Host("localhost").Port(11222); RemoteCacheManager rcm = new RemoteCacheManager(b.Build()); IRemoteCache cache = rcm.GetCache("functional_cache"); Test(cache); rcm.Stop(); } } }