/// <summary> /// Initializes a new instance of the <see cref="MembaseCache"/> class. /// </summary> /// <param name="regionName">Name of the region.</param> /// <param name="properties">The properties.</param> /// <param name="client">The client.</param> public MembaseCache(string regionName, IDictionary<string, string> properties, MembaseClient client) { this.region = regionName; this.client = client; this.expiry = 300; if (properties != null) { string expirationString = GetExpirationString(properties); if (expirationString != null) { this.expiry = Convert.ToInt32(expirationString, System.Globalization.CultureInfo.InvariantCulture); if (log.IsDebugEnabled) { log.DebugFormat("using expiration of {0} seconds", this.expiry); } } if (properties.ContainsKey("regionPrefix")) { this.regionPrefix = properties["regionPrefix"]; if (log.IsDebugEnabled) { log.DebugFormat("new regionPrefix :{0}", this.regionPrefix); } } else { if (log.IsDebugEnabled) { log.Debug("no regionPrefix value given, using defaults"); } } } }
static void Main(string[] args) { log4net.Config.XmlConfigurator.Configure(); // or just initialize the client from code var nscc = new MembaseClientConfiguration(); nscc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 2); nscc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10); nscc.Urls.Add(new Uri("http://192.168.2.160:8091/pools/default")); //nscc.Urls.Add(new Uri("http://192.168.2.162:8091/pools/default")); //nscc.Credentials = new NetworkCredential("A", "11111111"); //nscc.Bucket = "content"; //nscc.BucketPassword = "******"; var client = new MembaseClient(nscc); Console.WriteLine("Store = " + client.Store(StoreMode.Set, "4q", 1, new TimeSpan(0, 0, 4))); Console.WriteLine("Setting expiration to the far future."); //Console.ReadLine(); client.Touch("4q", DateTime.Now.AddDays(1)); Console.WriteLine("Wait for 4 sec."); Console.ReadLine(); Console.WriteLine(client.Get("4q") ?? "<null>"); //new MembaseClient(nscc, "data", "data").Store(StoreMode.Set, "q4", 2); //new MembaseClient(nscc, "feedback", null).Store(StoreMode.Set, "q4", 2); Console.ReadLine(); //nscc.PerformanceMonitorFactory = new Membase.Configuration.DefaultPerformanceMonitorFactory(); //nscc.BucketPassword = "******"; //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc), "TesT_A_")); //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient("content", "content"), "TesT_B_")); //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_B_")); //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_C_")); //ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_D_")); Console.ReadLine(); return; var mcc = new MemcachedClientConfiguration(); mcc.AddServer("192.168.2.200:11211"); mcc.AddServer("192.168.2.202:11211"); mcc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 4); mcc.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 4); mcc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10); StressTest(new MemcachedClient(mcc), "TesT_"); return; var nc = new MembaseClient(nscc, "content", "content"); var stats1 = nc.Stats("slabs"); foreach (var kvp in stats1.GetRaw("curr_connections")) { Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value); } var nc2 = new MembaseClient(nscc, "content", "content"); var stats2 = nc2.Stats(); foreach (var kvp in stats2.GetRaw("curr_connections")) { Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value); } }
static void Main(string[] args) { log4net.Config.XmlConfigurator.Configure(); var mbcc = new MembaseClientConfiguration(); mbcc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 2); mbcc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10); mbcc.Urls.Add(new Uri("http://localhost:8091/pools/default")); var client = new MembaseClient(mbcc); var item1 = client.Cas(StoreMode.Set, "item1", 1); var item2 = client.Cas(StoreMode.Set, "item2", 2); var add1 = client.Cas(StoreMode.Add, "item1", 4); Console.WriteLine(add1.Result); Console.WriteLine(add1.Cas); Console.WriteLine(add1.StatusCode); Console.WriteLine("item1 = " + item1.Cas); Console.WriteLine("item2 = " + item2.Cas); Console.WriteLine("Go?"); Console.ReadLine(); var mre = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(o => { mre.WaitOne(); Console.WriteLine("Waiting before change 1"); Thread.Sleep(4000); Console.WriteLine("item1 overwrite = " + client.Cas(StoreMode.Set, "item1", 4, item1.Cas).Result); Console.WriteLine("Waiting before change 2"); Thread.Sleep(4000); Console.WriteLine("item2 overwrite = " + client.Cas(StoreMode.Set, "item2", 4, item2.Cas).Result); }); //mre.Set(); //client.Sync("item1", item1.Cas, SyncMode.Mutation); client.Sync(SyncMode.Mutation, new[] { new KeyValuePair <string, ulong>("item1", item1.Cas), new KeyValuePair <string, ulong>("item2", item2.Cas) }); Console.WriteLine("Changed"); Console.ReadLine(); ////nscc.PerformanceMonitorFactory = new Membase.Configuration.DefaultPerformanceMonitorFactory(); ////nscc.BucketPassword = "******"; ////ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc), "TesT_A_")); ////ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient("content", "content"), "TesT_B_")); ////ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_B_")); ////ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_C_")); ////ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_D_")); //Console.ReadLine(); //return; //var mcc = new MemcachedClientConfiguration(); //mcc.AddServer("192.168.2.200:11211"); //mcc.AddServer("192.168.2.202:11211"); //mcc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 4); //mcc.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 4); //mcc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10); //StressTest(new MemcachedClient(mcc), "TesT_"); //return; //var nc = new MembaseClient(nscc, "content", "content"); //var stats1 = nc.Stats("slabs"); //foreach (var kvp in stats1.GetRaw("curr_connections")) // Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value); //var nc2 = new MembaseClient(nscc, "content", "content"); //var stats2 = nc2.Stats(); //foreach (var kvp in stats2.GetRaw("curr_connections")) // Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value); }
/// <summary> /// Callback to perform any necessary initialization of the underlying cache implementation /// during ISessionFactory construction. /// </summary> /// <param name="properties">current configuration settings</param> public void Start(IDictionary<string, string> properties) { lock (syncObject) { if (config == null) { throw new ConfigurationErrorsException("Configuration for membase not found"); } if (clientInstance == null) { clientInstance = new MembaseClient(config); } } }
/// <summary> /// Callback to perform any necessary cleanup of the underlying cache implementation /// during <see cref="M:NHibernate.ISessionFactory.Close"/>. /// </summary> public void Stop() { lock (syncObject) { clientInstance.Dispose(); clientInstance = null; } }
static void Main(string[] args) { log4net.Config.XmlConfigurator.Configure(); var mbcc = new MembaseClientConfiguration(); mbcc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 2); mbcc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10); mbcc.Urls.Add(new Uri("http://localhost:8091/pools/default")); var client = new MembaseClient(mbcc); var item1 = client.Cas(StoreMode.Set, "item1", 1); var item2 = client.Cas(StoreMode.Set, "item2", 2); var add1 = client.Cas(StoreMode.Add, "item1", 4); Console.WriteLine(add1.Result); Console.WriteLine(add1.Cas); Console.WriteLine(add1.StatusCode); Console.WriteLine("item1 = " + item1.Cas); Console.WriteLine("item2 = " + item2.Cas); Console.WriteLine("Go?"); Console.ReadLine(); var mre = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(o => { mre.WaitOne(); Console.WriteLine("Waiting before change 1"); Thread.Sleep(4000); Console.WriteLine("item1 overwrite = " + client.Cas(StoreMode.Set, "item1", 4, item1.Cas).Result); Console.WriteLine("Waiting before change 2"); Thread.Sleep(4000); Console.WriteLine("item2 overwrite = " + client.Cas(StoreMode.Set, "item2", 4, item2.Cas).Result); }); //mre.Set(); //client.Sync("item1", item1.Cas, SyncMode.Mutation); client.Sync(SyncMode.Mutation, new[] { new KeyValuePair<string, ulong>("item1", item1.Cas), new KeyValuePair<string, ulong>("item2", item2.Cas) }); Console.WriteLine("Changed"); Console.ReadLine(); ////nscc.PerformanceMonitorFactory = new Membase.Configuration.DefaultPerformanceMonitorFactory(); ////nscc.BucketPassword = "******"; ////ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc), "TesT_A_")); ////ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient("content", "content"), "TesT_B_")); ////ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_B_")); ////ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_C_")); ////ThreadPool.QueueUserWorkItem(o => StressTest(new MembaseClient(nscc, "default"), "TesT_D_")); //Console.ReadLine(); //return; //var mcc = new MemcachedClientConfiguration(); //mcc.AddServer("192.168.2.200:11211"); //mcc.AddServer("192.168.2.202:11211"); //mcc.SocketPool.ReceiveTimeout = new TimeSpan(0, 0, 4); //mcc.SocketPool.ConnectionTimeout = new TimeSpan(0, 0, 4); //mcc.SocketPool.DeadTimeout = new TimeSpan(0, 0, 10); //StressTest(new MemcachedClient(mcc), "TesT_"); //return; //var nc = new MembaseClient(nscc, "content", "content"); //var stats1 = nc.Stats("slabs"); //foreach (var kvp in stats1.GetRaw("curr_connections")) // Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value); //var nc2 = new MembaseClient(nscc, "content", "content"); //var stats2 = nc2.Stats(); //foreach (var kvp in stats2.GetRaw("curr_connections")) // Console.WriteLine("{0} -> {1}", kvp.Key, kvp.Value); }
/// <summary> /// Default Constructor /// </summary> /// <param name="cacheTime">The time to store stuff for</param> /// <param name="bucket">The bucket.</param> /// <param name="password">The password.</param> public MemcachedProvider(TimeSpan cacheTime, string bucket, string password) { _cacheTime = cacheTime; _bucket = bucket; _client = new MembaseClient(bucket, password); }