Exemplo n.º 1
0
        public void StatisticsTest()
        {
            Client.FlushAll();

            Client.TrySetValue("x", "안녕하세요").Should().Be.True();

            object value;

            Client.TryGetValue("x", out value).Should().Be.True();

            Client.FlushAll();
        }
Exemplo n.º 2
0
 /// <summary>
 /// 清空缓存
 /// </summary>
 public static void FlushCache()
 {
     using (MemcachedClient mc = new MemcachedClient())
     {
         mc.FlushAll();
     }
 }
        protected override MemcachedClient GetClient()
        {
            MemcachedClient client = new MemcachedClient("test/binaryConfig");
            client.FlushAll();

            return client;
        }
Exemplo n.º 4
0
 public static void Invalidate_Cache()
 {
     if (defaultCache != null)
     {
         defaultCache.FlushAll();
     }
 }
 /// <summary>
 /// 清空缓存
 /// </summary>
 public static void FlushCache()
 {
     if (IsUsedCache)
     {
         Mc.FlushAll();
     }
 }
Exemplo n.º 6
0
 public void FlushAll()
 {
     Execute(delegate
     {
         _client.FlushAll();
     });
 }
        protected override MemcachedClient GetClient()
        {
            MemcachedClient client = new MemcachedClient("test/textConfig");

            client.FlushAll();

            return(client);
        }
Exemplo n.º 8
0
 public MemcachedCache()
 {
     if (_client == null)
     {
         _client = new MemcachedClient();
         _client.FlushAll();
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Removes all data from the cache.
        /// </summary>
        public override void Purge()
        {
            if (!Connected)
            {
                throw new CacheNotConnectedException();
            }

            _memcachedClient.FlushAll();
        }
Exemplo n.º 10
0
        /// <summary>
        /// 移除键中所有的缓存
        /// </summary>
        /// <returns>返回缓存中项的数量</returns>
        public int Clear()
        {
            int count = 0;

            if (this.enable)
            {
                cache.FlushAll();
            }
            return(count);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 移除键中所有的缓存
        /// </summary>
        /// <returns>返回缓存中项的数量</returns>
        public int Clear()
        {
            var count = 0;

            if (this._enable)
            {
                _cache.FlushAll();
            }
            return(count);
        }
Exemplo n.º 12
0
 public virtual void Remove()
 {
     if (null != _client)
     {
         _client.FlushAll();
     }
     if (null != _logger)
     {
         _logger.Error("the distribute client is null.");
     }
 }
Exemplo n.º 13
0
        public static void ClearDatabase(string host, int port)
        {
            var config = new MemcachedClientConfiguration();

            config.AddServer(host, port);

            using (var client = new MemcachedClient(config))
            {
                client.FlushAll();
            }
        }
Exemplo n.º 14
0
 /// <summary>
 /// 构造函数
 /// </summary>
 private MMemcache()
 {
     try
     {
         _cacheClient = new MemcachedClient();
         _cacheClient.FlushAll();
     }
     catch (Exception ex)
     {
         MLogManager.Error(MLogGroup.Other.Memcached缓存, null, "缓存初始化失败!", ex);
     }
 }
Exemplo n.º 15
0
 internal static bool Flush()
 {
     try
     {
         ConnectMemcachedClient();
         memcachedClient.FlushAll();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 16
0
        static MemcachedHelper()
        {
            try
            {
                ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
                fileMap.ExeConfigFilename = configPath;

                Configuration configuration = ConfigurationManager
                                              .OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
                if (configuration == null || configuration.AppSettings == null || configuration.AppSettings == null)
                {
                    throw new Exception("未找到Memcahce配置文件,请先配置文件");
                }

                string   server     = configuration.AppSettings.Settings["serverList"].Value;
                string[] serverList = { server };
                // 初始化SocketIO池
                string     poolName   = configuration.AppSettings.Settings["poolName"].Value;//"MemcachedPool";
                SockIOPool sockIOPool = SockIOPool.GetInstance(poolName);
                // 添加服务器列表
                sockIOPool.SetServers(serverList);
                // 设置连接池初始数目
                sockIOPool.InitConnections = int.Parse(configuration.AppSettings.Settings["InitConnections"].Value);           //10;
                // 设置连接池最小连接数目
                sockIOPool.MinConnections = int.Parse(configuration.AppSettings.Settings["MinConnections"].Value);             //10;
                // 设置连接池最大连接数目
                sockIOPool.MaxConnections = int.Parse(configuration.AppSettings.Settings["MaxConnections"].Value);             //200;
                // 设置连接的套接字超时时间(单位:毫秒)
                sockIOPool.SocketConnectTimeout = int.Parse(configuration.AppSettings.Settings["SocketConnectTimeout"].Value); // 2000;
                // 设置套接字超时时间(单位:毫秒)
                sockIOPool.SocketTimeout = int.Parse(configuration.AppSettings.Settings["SocketTimeout"].Value);               // 4000;
                // 设置维护线程运行的睡眠时间:如果设置为0,那么维护线程将不会启动
                sockIOPool.MaintenanceSleep = int.Parse(configuration.AppSettings.Settings["MaintenanceSleep"].Value);         //30;
                // 设置SockIO池的故障标志
                sockIOPool.Failover = configuration.AppSettings.Settings["Failover"].Value.Equals("true")?true:false;          //true;
                // 是否用nagle算法启动
                sockIOPool.Nagle = configuration.AppSettings.Settings["Nagle"].Value.Equals("true") ? true : false;            //false;
                // 正式初始化容器
                sockIOPool.Initialize();

                mclient                   = new MemcachedClient();
                mclient.PoolName          = poolName;
                mclient.EnableCompression = configuration.AppSettings.Settings["EnableCompression"].Value.Equals("true") ? true : false;//false;
                mclient.FlushAll();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 17
0
 /// <summary>
 /// 删除缓存
 /// </summary>
 /// <param name="keys"></param>
 /// <returns></returns>
 public static void Remove(params string[] keys)
 {
     if (keys == null || keys.Length <= 0)
     {
         Client.FlushAll();
     }
     else
     {
         foreach (var key in keys)
         {
             Remove(key);
         }
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// 清除所有缓存
        /// </summary>
        /// <returns></returns>
        public bool Clear()
        {
            var result = true;

            try
            {
                _cacheClient.FlushAll();
            }
            catch
            {
                result = false;
            }
            return(result);
        }
        public void Add_Study()
        {
            using (var client = new MemcachedClient())
            {
                var result1 = client.Store(StoreMode.Add, "userid", "123456");
                Assert.True(result1);

                // 不可以多次调用
                var result2 = client.Store(StoreMode.Add, "userid", "123456");
                Assert.False(result2);

                client.FlushAll();
            }
        }
        public void Get_Study()
        {
            using (var client = new MemcachedClient())
            {
                // 没有键,返回null。
                var result1 = client.Get("userid");
                Assert.Null(result1);

                client.Store(StoreMode.Set, "userid", "123456");
                var result2 = client.Get("userid");
                Assert.AreEqual("123456", result2);

                client.FlushAll();
            }
        }
        public void Replace_Study()
        {
            using (var client = new MemcachedClient())
            {
                // 没有键,不能替换。
                var result1 = client.Store(StoreMode.Replace, "userid", "123456");
                Assert.False(result1);

                // 有的话,就可以。
                client.Store(StoreMode.Add, "userid", "123456");
                var result2 = client.Store(StoreMode.Replace, "userid", "123456");
                Assert.True(result2);

                client.FlushAll();
            }
        }
Exemplo n.º 22
0
        public void FlushTest()
        {
            MemcachedClient mc = new MemcachedClient();

            mc.Store(StoreMode.Set, "qwer", "1");
            mc.Store(StoreMode.Set, "tyui", "1");
            mc.Store(StoreMode.Set, "polk", "1");
            mc.Store(StoreMode.Set, "mnbv", "1");
            mc.Store(StoreMode.Set, "zxcv", "1");
            mc.Store(StoreMode.Set, "gfsd", "1");

            Assert.AreEqual("1", mc.Get("mnbv"), "Setup for FlushAll() failed");

            mc.FlushAll();

            Assert.IsNull(mc.Get("qwer"), "FlushAll() failed.");
            Assert.IsNull(mc.Get("tyui"), "FlushAll() failed.");
            Assert.IsNull(mc.Get("polk"), "FlushAll() failed.");
            Assert.IsNull(mc.Get("mnbv"), "FlushAll() failed.");
            Assert.IsNull(mc.Get("zxcv"), "FlushAll() failed.");
            Assert.IsNull(mc.Get("gfsd"), "FlushAll() failed.");
        }
Exemplo n.º 23
0
        public void FlushTest()
        {
            using (MemcachedClient client = GetClient())
            {
                Assert.IsTrue(client.Store(StoreMode.Set, "qwer", "1"), "Initialization failed");
                Assert.IsTrue(client.Store(StoreMode.Set, "tyui", "1"), "Initialization failed");
                Assert.IsTrue(client.Store(StoreMode.Set, "polk", "1"), "Initialization failed");
                Assert.IsTrue(client.Store(StoreMode.Set, "mnbv", "1"), "Initialization failed");
                Assert.IsTrue(client.Store(StoreMode.Set, "zxcv", "1"), "Initialization failed");
                Assert.IsTrue(client.Store(StoreMode.Set, "gfsd", "1"), "Initialization failed");

                Assert.AreEqual("1", client.Get("mnbv"), "Setup for FlushAll() failed");

                client.FlushAll();

                Assert.IsNull(client.Get("qwer"), "FlushAll() failed.");
                Assert.IsNull(client.Get("tyui"), "FlushAll() failed.");
                Assert.IsNull(client.Get("polk"), "FlushAll() failed.");
                Assert.IsNull(client.Get("mnbv"), "FlushAll() failed.");
                Assert.IsNull(client.Get("zxcv"), "FlushAll() failed.");
                Assert.IsNull(client.Get("gfsd"), "FlushAll() failed.");
            }
        }
Exemplo n.º 24
0
        //删除
        protected void Button4_Click(object sender, EventArgs e)
        {
            GetDb(out MemcachedClient MClient);
            if (MClient.KeyExists("key1"))
            {
                bool t = MClient.Delete("key1");

                //清除所有的缓存
                MClient.FlushAll();
                if (t == true)
                {
                    Response.Write("<script>alert('删除成功!')</script>");
                }
                else
                {
                    Response.Write("<script>alert('删除失败!')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('删除失败!')</script>");
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// 清空缓存服务器上的缓存
        /// </summary>
        public void FlushCache()
        {
            MemcachedClient mc = getInstance();

            mc.FlushAll();
        }
        public void Gets_Study()
        {
            using (var client = new MemcachedClient())
            {
                /* 
                 * 非常重要的CAS操作 
                 */

                client.Store(StoreMode.Set, "userid", "123456");
                var result = client.GetWithCas("userid");

                Assert.AreEqual("123456", result.Result);
                Assert.Greater(result.Cas, 0u);

                client.FlushAll();
            }
        }
Exemplo n.º 27
0
 public void Clear()
 {
     MemClient.FlushAll();
 }
Exemplo n.º 28
0
 public void ClearCacheAll()
 {
     memcachedClient.FlushAll();
 }
Exemplo n.º 29
0
 public override void Clear()
 {
     client.FlushAll();
 }
 public void Flush()
 {
     cache.FlushAll();
 }
Exemplo n.º 31
0
 public void ClearAllCaches()
 {
     _cache.FlushAll();
 }
Exemplo n.º 32
0
 public override bool RemoveAll()
 {
     return(cache.FlushAll());
 }
        public void Delete_Study()
        {
            using (var client = new MemcachedClient())
            {
                // 没有键,返回false。
                var result1 = client.Remove("userid");
                Assert.False(result1);

                client.Store(StoreMode.Set, "userid", "123456");
                var result2 = client.Remove("userid");
                Assert.True(result2);

                client.FlushAll();
            }
        }
Exemplo n.º 34
0
 /// <summary>
 /// Remove all data from cache
 /// </summary>
 public override void RemoveAllCached() => _cached.FlushAll();
Exemplo n.º 35
0
        public void DataContext_Caching_UserSpecificIndexUpdatedByFullIndex()
        {
            cacheClient.FlushAll();
            this._cacheHitCount = 0;

            var ctx = TestConfiguration.GetDataContext(tablePrefix);

            var fullTable = ctx.GetTable <FullEntity>(() =>
            {
                var cache    = new EnyimTableCache(cacheClient, TimeSpan.MaxValue);
                cache.OnLog += s => Debug.WriteLine("{0} FullEntityCache: {1}", DateTime.Now, s);
                cache.OnHit += this.OnCacheHit;
                return(cache);
            });

            var userSpecificTable1 = ctx.GetTable <UserEntity>
                                     (
                userId1,
                () =>
            {
                var cache    = new EnyimTableCache(cacheClient, TimeSpan.MaxValue);
                cache.OnLog += s => Debug.WriteLine("{0} UserEntityCache1: {1}", DateTime.Now, s);
                cache.OnHit += this.OnCacheHit;
                return(cache);
            }
                                     );

            var userSpecificTable2 = ctx.GetTable <UserEntity>
                                     (
                userId2,
                () =>
            {
                var cache    = new EnyimTableCache(cacheClient, TimeSpan.MaxValue);
                cache.OnLog += s => Debug.WriteLine("{0} UserEntityCache2: {1}", DateTime.Now, s);
                cache.OnHit += this.OnCacheHit;
                return(cache);
            }
                                     );

            var fullQuery          = from en in fullTable where en.DateTimeField >= dtNow && (intRange.Contains(en.IntField)) select en;
            var userSpecificQuery1 = from en in userSpecificTable1 where en.DateTimeField >= dtNow && (intRange.Contains(en.IntField)) select en;
            var userSpecificQuery2 = from en in userSpecificTable2 where en.DateTimeField < dtNow && en.IntField < 3 select en;

            // loading indexes - they should be put to cache
            Assert.AreEqual(2, fullQuery.AsEnumerable().Count(), "Failed to load full query from table");
            Assert.AreEqual(1, userSpecificQuery1.AsEnumerable().Count(), "Failed to load user-specific query1 from table");
            Assert.AreEqual(0, userSpecificQuery2.AsEnumerable().Count(), "The user-specific query2 should return 0 entities");
            Assert.AreEqual(0, this._cacheHitCount, "Cache wasn't flushed for some strange reason");

            // now loading from cache
            Assert.AreEqual(2, fullQuery.AsEnumerable().Count(), "Failed to load full query from cache");
            Assert.AreEqual(1, userSpecificQuery1.AsEnumerable().Count(), "Failed to load user-specific query from cache");
            Assert.AreEqual(0, userSpecificQuery2.AsEnumerable().Count(), "The user-specific query2 should return 0 entities");
            Assert.AreEqual(3, this._cacheHitCount, "The queries were not loaded from cache");

            // now adding 2 new entities - they should appear in both indexes
            fullTable.InsertOnSubmit
            (
                new FullEntity()
            {
                HashKey       = userId1,
                RangeKey      = rangeKey5,
                DateTimeField = dtNow + TimeSpan.FromDays(1000),
                IntField      = 5
            }
            );
            fullTable.InsertOnSubmit
            (
                new FullEntity()
            {
                HashKey       = userId1,
                RangeKey      = rangeKey4,
                DateTimeField = dtNow + TimeSpan.FromDays(9999),
                IntField      = 4
            }
            );
            ctx.SubmitChanges();

            this._cacheHitCount = 0;

            // now loading from cache
            Assert.AreEqual(4, fullQuery.AsEnumerable().Count(), "Failed to load full query from cache");
            Assert.AreEqual(3, userSpecificQuery1.AsEnumerable().Count(), "Failed to load user-specific query from cache");
            Assert.AreEqual(0, userSpecificQuery2.AsEnumerable().Count(), "The user-specific query2 should return 0 entities");
            Assert.AreEqual(3, this._cacheHitCount, "The queries were not loaded from cache");


            // now removing a couple of entities

            fullTable.RemoveOnSubmit(new FullEntity()
            {
                HashKey = userId1, RangeKey = rangeKey1
            });
            fullTable.RemoveOnSubmit(new FullEntity()
            {
                HashKey = userId1, RangeKey = rangeKey3
            });
            ctx.SubmitChanges();

            this._cacheHitCount = 0;

            // now loading from cache
            Assert.AreEqual(3, fullQuery.AsEnumerable().Count(), "Failed to load full query from cache");
            Assert.AreEqual(2, userSpecificQuery1.AsEnumerable().Count(), "Failed to load user-specific query from cache");
            Assert.AreEqual(0, userSpecificQuery2.AsEnumerable().Count(), "The user-specific query2 should return 0 entities");
            Assert.AreEqual(3, this._cacheHitCount, "The queries were not loaded from cache");

            // now loading from DynamoDb again
            cacheClient.FlushAll();
            this._cacheHitCount = 0;

            Assert.AreEqual(3, fullQuery.AsEnumerable().Count(), "Failed to load full query from cache");
            Assert.AreEqual(2, userSpecificQuery1.AsEnumerable().Count(), "Failed to load user-specific query from cache");
            Assert.AreEqual(0, userSpecificQuery2.AsEnumerable().Count(), "The user-specific query2 should return 0 entities");
            Assert.AreEqual(0, this._cacheHitCount, "Cache wasn't flushed for some strange reason");
        }
Exemplo n.º 36
0
 public bool FlushAll()
 {
     return(_mclient.FlushAll());
 }
        public void Cas_Study()
        {
            using (var client = new MemcachedClient())
            {
                /* 
                 * 非常重要的CAS操作 
                 */

                client.Store(StoreMode.Set, "userid", "123456");
                var result1 = client.GetWithCas("userid");
                var result2 = client.Cas(StoreMode.Set, "userid", "6543321");
                Assert.True(result2.Result);
                var result3 = client.Cas(StoreMode.Set, "userid", "123456", result1.Cas);
                Assert.False(result3.Result);

                client.FlushAll();
            }
        }
Exemplo n.º 38
0
		public void FlushTest()
		{
			MemcachedClient mc = new MemcachedClient();
			mc.Store(StoreMode.Set, "qwer", "1");
			mc.Store(StoreMode.Set, "tyui", "1");
			mc.Store(StoreMode.Set, "polk", "1");
			mc.Store(StoreMode.Set, "mnbv", "1");
			mc.Store(StoreMode.Set, "zxcv", "1");
			mc.Store(StoreMode.Set, "gfsd", "1");

			Assert.AreEqual("1", mc.Get("mnbv"), "Setup for FlushAll() failed");

			mc.FlushAll();

			Assert.IsNull(mc.Get("qwer"), "FlushAll() failed.");
			Assert.IsNull(mc.Get("tyui"), "FlushAll() failed.");
			Assert.IsNull(mc.Get("polk"), "FlushAll() failed.");
			Assert.IsNull(mc.Get("mnbv"), "FlushAll() failed.");
			Assert.IsNull(mc.Get("zxcv"), "FlushAll() failed.");
			Assert.IsNull(mc.Get("gfsd"), "FlushAll() failed.");
		}
Exemplo n.º 39
0
 /// <summary>
 /// 清空缓存
 /// </summary>
 public static void FlushCache()
 {
     using (MemcachedClient mc = new MemcachedClient())
     {
         mc.FlushAll();
     }
 }