小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

分布式緩存MemCache

 昵稱10504424 2013-07-16

.NET版本服務(wù)端    http://pan.baidu.com/share/link?shareid=3505343637&uk=3928651495

.NET版本客戶端    http://pan.baidu.com/share/link?shareid=3511558869&uk=3928651495

封裝類

復(fù)制代碼
/// <summary>
    /// MemCache幫助類
    /// 根據(jù)配置文件里的Serverlist節(jié)點(diǎn)讀取分布式緩存服務(wù)器列表 格式為 "127.0.0.1:11211" ,"127.0.0.2:11211" 
    /// 如果Web.config未配置。則服務(wù)器默認(rèn)為 127.0.0.1:11211
    /// </summary>
    public class CachedHelper
    {

        /// <summary>
        /// 設(shè)置緩存_如果KEY存在_則更新
        /// </summary>
        /// <param name="Key">Key</param>
        /// <param name="Value">Value</param>
        /// <param name="times">過期時間點(diǎn)_為當(dāng)前時間加上此值(單位為妙)</param>
        public static void SetMemCache(string Key, object Value, double times)
        {
            SockIOPool pool;
            MemcachedClient mc;
            init(out pool, out mc);
            mc.Set(Key, Value, DateTime.Now.AddSeconds(times));
            pool.Shutdown();//關(guān)閉連接池
        }

        /// <summary>
        /// 設(shè)置緩存_如果KEY存在_則更新
        /// </summary>
        /// <param name="Key">Key</param>
        /// <param name="Value">Value</param>
        public static void SetMemCache(string Key, object Value)
        {

            SockIOPool pool;
            MemcachedClient mc;
            init(out pool, out mc);
            mc.Set(Key, Value);
            pool.Shutdown();//關(guān)閉連接池
        }

        /// <summary>
        /// 根據(jù)Key讀取緩存_如果讀不到_返回空字符串
        /// </summary>
        /// <param name="Key"></param>
        /// <returns></returns>
        public static object GetMemcache(string Key)
        {
            SockIOPool pool;
            MemcachedClient mc;
            init(out pool, out mc);
            object value = mc.Get(Key) ?? "";
            pool.Shutdown();//關(guān)閉連接池
            return value;

        }
        /// <summary>
        /// 服務(wù)器初始化
        /// </summary>
        /// <param name="pool"></param>
        /// <param name="mc"></param>
        private static void init(out SockIOPool pool, out MemcachedClient mc)
        {
            string ConServerlist = System.Configuration.ConfigurationManager.AppSettings.Get("Serverlist");
            if (string.IsNullOrEmpty(ConServerlist))
            {
                ConServerlist = "127.0.0.1:11211";
            }
            ///初始化memcached 服務(wù)器端集群列表。
            string[] serverlist = ConServerlist.Split(',');
            pool = SockIOPool.GetInstance("MemCache");
            //設(shè)置怎么mem池連接點(diǎn)服務(wù)器端。
            pool.SetServers(serverlist);
            pool.Initialize();
            //創(chuàng)建了一個mem客戶端的代理類。
            mc = new MemcachedClient();
            mc.PoolName = "MemCache";
            mc.EnableCompression = false;
        }


    }

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多