/// <summary>
        /// 删除cache
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_removecache_click(object sender, EventArgs e)
        {
            MemcachedClient cache = new MemcachedClient();

            //获取负载服务器集合
            string[] serverlist = OperateParam.SplitByComma(ConfigurationManager.AppSettings["MemCacheServers"]);
            //初始化池
            SockIOPool pool = SockIOPool.GetInstance();

            pool.SetServers(serverlist);
            pool.Initialize();
            cache.Delete("TestCache");//删除cache
        }
Exemplo n.º 2
0
 public void Clear(string sessionId = null)
 {
     if (string.IsNullOrEmpty(sessionId))
     {
         sessionId = GetSessionId();
         //sessionId = null说明是删自己的session,要删除cookie
         DeleteCookie();
     }
     if (!string.IsNullOrEmpty(sessionId))
     {
         mc.Delete(sessionId);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 移除键中某关键字的缓存并返回相应的值
        /// </summary>
        /// <param name="key">关键字</param>
        public void Remove(string key)
        {
            object result = null;

            if (this.enable && this.Contains(key))
            {
                if (this.Contains(key))
                {
                    result = cache.Get(key);
                    cache.Delete(key);
                }
            }
            return;
        }
Exemplo n.º 4
0
 /// <summary>
 /// 删除缓存
 /// </summary>
 public void Remove(string key)
 {
     try
     {
         SockIOPool pool = GetPool();
         memcache.PoolName          = poolName;
         memcache.EnableCompression = true;
         memcache.Delete(key);
     }
     catch
     {
         throw;
     }
 }
Exemplo n.º 5
0
 public static bool Delete(string poolName, string key)
 {
     try
     {
         MemcachedClient mc = MemcacheItem.GetInstance(poolName);
         mc.PoolName = poolName;
         return(mc.Delete(key));
     }
     catch (Exception ex)
     {
         LogEngine.Write(LOGTYPE.ERROR, "MemcacheItem Delete ex:", ex.ToString());
         return(false);
     }
 }
Exemplo n.º 6
0
        public void TestDelete()
        {
            //Test Delete
            MemcachedClient mc = new MemcachedClient();

            if (mc.KeyExists("SetTest"))
            {
                mc.Delete("SetTest", null, DateTime.MaxValue);
                if (!mc.KeyExists("SetTest"))
                {
                    HandleLogs("[Cmd=Delete]Key为SetTest的值已经被删除");
                }
            }
        }
Exemplo n.º 7
0
 public static bool DeleteAferExpire(string poolName, string key, int expireSecs)
 {
     try
     {
         MemcachedClient mc = MemcacheItem.GetInstance(poolName);
         mc.PoolName = poolName;
         return(mc.Delete(key, DateTime.Now.AddSeconds(expireSecs)));
     }
     catch (Exception ex)
     {
         LogEngine.Write(LOGTYPE.ERROR, "MemcacheItem DeleteAferExpire ex:", ex.ToString());
         return(false);
     }
 }
Exemplo n.º 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            string[] serverlist = { "127.0.0.1:11211", "172.0.0.1:11211" };
            //初始化池
            SockIOPool pool = SockIOPool.GetInstance();

            pool.SetServers(serverlist);
            pool.InitConnections      = 3;
            pool.MinConnections       = 3;
            pool.MaxConnections       = 5;
            pool.SocketConnectTimeout = 1000;
            pool.SocketTimeout        = 3000;
            pool.MaintenanceSleep     = 30;
            pool.Failover             = true;
            pool.Nagle = false;
            pool.Initialize();
            // 获得客户端实例
            MemcachedClient mc = new MemcachedClient();

            mc.EnableCompression = false;
            Console.WriteLine("------------测  试-----------");
            mc.Set("test", "my value");      //存储数据到缓存服务器,这里将字符串"my value"缓存,key 是"test"
            if (mc.KeyExists("test"))        //测试缓存存在key为test的项目
            {
                Console.WriteLine("test is Exists");
                Console.WriteLine(mc.Get("test").ToString());                 //在缓存中获取key为test的项目
            }
            else
            {
                Console.WriteLine("test not Exists");
            }

            Console.ReadLine();

            mc.Delete("test");  //移除缓存中key为test的项目

            if (mc.KeyExists("test"))
            {
                Console.WriteLine("test is Exists");
                Console.WriteLine(mc.Get("test").ToString());
            }
            else
            {
                Console.WriteLine("test not Exists");
            }
            Console.ReadLine();

            SockIOPool.GetInstance().Shutdown(); //关闭池, 关闭sockets
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            string[] serverList = { "192.168.199.130:11211" };
            //创建一个Memcache连接池
            SockIOPool sockPool = SockIOPool.GetInstance("MemcachedPool");

            //Set Memcache Server List
            sockPool.SetServers(serverList);
            // Set Servers Initial Connections Number
            sockPool.InitConnections = 3;
            sockPool.MinConnections  = 3;
            sockPool.MaxConnections  = 5;

            //Set TimeOut of Connection
            sockPool.SocketConnectTimeout = 1000;
            //Set TimeOut of Reads
            sockPool.SocketTimeout = 3000;

            sockPool.MaintenanceSleep = 30;
            sockPool.Failover         = true;

            sockPool.Nagle = false;
            sockPool.Initialize();

            MemcachedClient mClient = new MemcachedClient();

            mClient.EnableCompression = false;
            mClient.PoolName          = "MemcachedPool";

            mClient.Set("key", "value");
            if (!mClient.KeyExists("key"))
            {
                Console.WriteLine("不存在该key");
            }
            else
            {
                Console.WriteLine(mClient.Get("key").ToString());
                mClient.Delete("key");
                if (!mClient.KeyExists("key"))
                {
                    Console.WriteLine("不存在该key");
                }
                else
                {
                    Console.WriteLine(mClient.Get("key").ToString());
                }
            }
            SockIOPool.GetInstance("MemcachedPool").Shutdown();
        }
Exemplo n.º 10
0
        public void TestGet()
        {
            MemcachedClient mc = new MemcachedClient();

            mc.Add("Get", "Get A Cmd=Get");
            if (mc.KeyExists("Get"))
            {
                Object o = mc.Get("Get");
                if (o != null)
                {
                    HandleLogs("[Cmd=Get]Get的值是:" + o.ToString());
                    mc.Delete("Get");
                }
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// 删掉Memcache 数据
 /// </summary>
 /// <param name="key"> </param>
 /// <returns></returns>
 public static bool RemoveCache(string pKey)
 {
     if (MemcacheHelperInit())
     {
         if (!mc.KeyExists(pKey))
         {
             return(false);
         }
         else
         {
             return(mc.Delete(pKey));
         }
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 12
0
 /// <summary>
 /// 删除指定缓存池的指定键的值
 /// </summary>
 /// <param name="poolName">缓存池名</param>
 /// <param name="key">缓存键</param>
 public static void DeleteMemcache(string poolName, string key)
 {
     try
     {
         SockIOPool instance = SockIOPool.GetInstance(poolName);
         instance.SetServers(CacheConfig.getMemcachedServerList());
         instance.SocketTimeout        = 3000;
         instance.SocketConnectTimeout = 3000;
         instance.Initialize();
         MemcachedClient memcachedClient = new MemcachedClient();
         memcachedClient.PoolName          = poolName;
         memcachedClient.EnableCompression = false;
         if (!memcachedClient.KeyExists(key))
         {
             return;
         }
         memcachedClient.Delete(key);
     }
     catch { }
 }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            //获取负载服务器集合
            string[] serverlist = SplitByComma(ConfigurationManager.AppSettings["MemCacheServers"]);
            //初始化池
            SockIOPool pool = SockIOPool.GetInstance();

            pool.SetServers(serverlist);
            pool.Initialize();

            MemcachedClient cache    = new MemcachedClient();
            var             getCache = cache.Get("TestCache");//获取cache

            if (getCache == null)
            {
                cache.Set("TestCache", "你好啊,memcache", DateTime.Now.AddHours(2));//获取不到则重新设置cache
                getCache = cache.Get("TestCache");
            }
            Console.WriteLine("获取到的cache为:" + getCache);
            cache.Delete("TestCache");//删除cache
            Console.Read();
        }
Exemplo n.º 14
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.º 15
0
 /// <summary>
 /// 删除缓存
 /// 使用:MemcacheHelper.GetInstance().Delete(key)
 /// </summary>
 /// <param name="key">需要删除的缓存的键</param>
 public void Delete(string key)
 {
     _client.Delete(key);
 }
Exemplo n.º 16
0
 public void Delete(string key)
 {
     MemcachedClient.Delete(key);
 }
Exemplo n.º 17
0
        /// <summary>
        /// 从缓存中删除
        /// </summary>
        /// <param name="key">键</param>
        /// <returns></returns>
        public bool DelValFromCache(string keyname, string identity)
        {
            string key = string.Format("{0}_{1}", keyname, identity);

            return(mc.Delete(key));
        }
Exemplo n.º 18
0
 public void ClearKey(string key)
 {
     _cache.Delete(key);
 }
Exemplo n.º 19
0
 public override object Remove(string key, string regionName = null)
 {
     _mclient.Delete(key);
     return(null);
 }
Exemplo n.º 20
0
 public bool RemoveObject(string key)
 {
     return(mc.Delete(key));
 }
Exemplo n.º 21
0
        public void Remove(string key)
        {
            MemcachedClient mcmain = CreateServer();

            mcmain.Delete(key);
        }
Exemplo n.º 22
0
 public void Remove(string key)
 {
     mc = MemcachedClient.GetInstance(CacheName);
     mc.Delete(key);
 }
Exemplo n.º 23
0
        /// <summary>
        /// 删除指定条件缓存
        /// </summary>
        /// <param name="server"></param>
        /// <param name="key">键</param>
        /// <param name="hashCode">哈希码</param>
        /// <param name="expiry">过期时间</param>
        public static bool DeleteFrom(string server, string key, int hashCode, DateTime expiry)
        {
            MemcachedClient client = GetClient(server);

            return(client.Delete(key, hashCode, expiry));
        }
Exemplo n.º 24
0
        ///  <summary>
        /// 删除指定条件缓存
        ///  </summary>
        /// <param name="server"></param>
        /// <param name="key">键</param>
        public static bool DeleteFrom(string server, string key)
        {
            MemcachedClient client = GetClient(server);

            return(client.Delete(key));
        }
Exemplo n.º 25
0
 public void Remove(string key)
 {
     client.Delete(key);
 }
Exemplo n.º 26
0
        static void Main(string[] args)
        {
            //参数设置
            string SockIOPoolName = "Test_SockIOPoolName";

            //分布Memcached服务IP 端口
            string[] MemcacheServiceList = { "127.0.0.1:11211" };

            //设置连接池
            SockIOPool SPool = SockIOPool.GetInstance(SockIOPoolName);

            SPool.SetServers(MemcacheServiceList);
            SPool.MaxConnections       = 5;
            SPool.MinConnections       = 3;
            SPool.InitConnections      = 3;
            SPool.SocketConnectTimeout = 1000;
            SPool.SocketTimeout        = 3000;
            SPool.Failover             = true;
            SPool.Nagle = false;
            SPool.Initialize();

            //实例化Client
            MemcachedClient MClient = new MemcachedClient();

            MClient.PoolName = SockIOPoolName;
            MClient.FlushAll();

            Console.WriteLine("1.创建memcache缓存Hello World");
            MClient.Add("Key1001", "Hello World");
            Console.WriteLine("2.查询缓存信息{0}", MClient.Get("Key1001"));

            Console.WriteLine("3.修改memcache缓存Hello World");
            MClient.Set("Key1001", "Hello World - 修改版");
            Console.WriteLine("4.查询缓存信息{0}", MClient.Get("Key1001"));

            if (MClient.KeyExists("Key1001"))
            {
                Console.WriteLine("5.删除memcache缓存");
                MClient.Delete("Key1001");
            }

            if (MClient.KeyExists("Key1001"))
            {
                Console.WriteLine(MClient.Get("Key1001"));
            }
            else
            {
                Console.WriteLine("6.删除已删除");
            }

            Student stud = new Student()
            {
                id = "10001", name = "张三"
            };

            MClient.Add("student", stud);
            Student Get_stud = MClient.Get("student") as Student;

            Console.WriteLine("6.缓存实体对象:{0} {1}", Get_stud.id, Get_stud.name);

            MClient.Add("Key1002", "我已设置过期时间1分钟", DateTime.Now.AddMinutes(1));
            while (true)
            {
                if (MClient.KeyExists("Key1002"))
                {
                    Console.WriteLine("key:Key1002 Value:{0},当前时间:{1}", MClient.Get("Key1002"), DateTime.Now);
                    Thread.Sleep(20000);
                }
                else
                {
                    Console.WriteLine("key:Key1002 我已过期,当前时间:{0}", DateTime.Now);
                    break;
                }
            }
            SPool.Shutdown();
        }
Exemplo n.º 27
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="key">键</param>
 /// <returns>操作是否成功</returns>
 public static bool Delete(string key)
 {
     return(mc.Delete(key));
 }
Exemplo n.º 28
0
 public override bool Remove(string key)
 {
     return(cache.Delete(key));
 }
Exemplo n.º 29
0
 public void RemoveCache(string key)
 {
     mc.Delete(key);
 }
Exemplo n.º 30
0
 public bool Delete(string guid)
 {
     return(client.Delete(guid));
 }