コード例 #1
0
 public CacheIdentify DistributedCacheSyncIdentify(CacheIdentify cacheId)
 {
     if (mConn == null)
     {
         throw new Exception("还没有创建连接!");
     }
     try
     {
         IWCFHandlerService _wcfService = mConn.WcfService;
         return(_wcfService.DistributedCacheSyncIdentify(cacheId));
     }
     catch (Exception e)
     {
         throw new Exception(e.Message + "\n连接服务主机失败,请联系管理员!");
     }
 }
コード例 #2
0
        /// <summary>
        /// 比较后不同的标识(下级的CacheIdentify与上级的对比)
        /// </summary>
        /// <returns></returns>
        private static CacheIdentify CompareCache(CacheIdentify _cacheId)
        {
            CacheIdentify cacheId = new CacheIdentify();

            cacheId.ServerIdentify = _cacheId.ServerIdentify;
            cacheId.cachename      = _cacheId.cachename;
            cacheId.identify       = _cacheId.identify;
            cacheId.keytimestamps  = new Dictionary <string, double>();
            //自己跟自己比较返回空
            if (_cacheId.ServerIdentify == WcfGlobal.Identify)
            {
                return(cacheId);
            }

            if (LocalCache.Contains(_cacheId.cachename))
            {
                CacheIdentify ci = GetCacheIdentify(_cacheId.cachename);
                if (_cacheId.identify != ci.identify)
                {
                    //循环判断待同步的新增和修改,本地时间搓小于远程时间搓就修改
                    foreach (var t in ci.keytimestamps)
                    {
                        //新增的
                        if (_cacheId.keytimestamps.ContainsKey(t.Key) == false)
                        {
                            cacheId.keytimestamps.Add(t);
                            continue;
                        }
                        //修改的
                        if (_cacheId.keytimestamps[t.Key] < t.Value)
                        {
                            cacheId.keytimestamps.Add(t);
                            continue;
                        }
                    }
                    //循环判断本地的删除,本地时间搓小于远程identify的就会删除
                    //删除是打删除标记,所以不存在移除,都进入修改列表
                }
                return(cacheId);
            }
            else
            {
                return(cacheId);
            }
        }
コード例 #3
0
        /// <summary>
        /// 获取本地缓存的标识
        /// </summary>
        private static CacheIdentify GetCacheIdentify(string cacheName)
        {
            CacheIdentify cacheId = new CacheIdentify();

            if (DistributedCacheManage.LocalCache.Contains(cacheName))
            {
                CacheObject co = DistributedCacheManage.LocalCache.GetData(cacheName) as CacheObject;
                cacheId.ServerIdentify = co.ServerIdentify;
                cacheId.cachename      = co.cachename;
                cacheId.identify       = co.identify;
                cacheId.keytimestamps  = new Dictionary <string, double>();
                foreach (var cd in co.cacheValue)
                {
                    cacheId.keytimestamps.Add(cd.key, cd.timestamp);
                }
            }
            return(cacheId);
        }
コード例 #4
0
        /// <summary>
        /// 获取待同步的缓存
        /// </summary>
        /// <returns></returns>
        private static CacheObject GetStayLocalCache(CacheIdentify identify)
        {
            CacheObject _co = new CacheObject();

            if (LocalCache.Contains(identify.cachename))
            {
                CacheObject co = LocalCache.GetData(identify.cachename) as CacheObject;
                _co.ServerIdentify = co.ServerIdentify;
                _co.cachename      = co.cachename;
                _co.identify       = co.identify;
                _co.cacheValue     = new List <CacheData>();
                foreach (var kt in identify.keytimestamps)
                {
                    CacheData cd = co.cacheValue.Find(x => (x.timestamp == kt.Value && x.key == kt.Key));//这个bug找了一晚
                    if (cd != null)
                    {
                        _co.cacheValue.Add(cd);
                    }
                }
            }
            return(_co);
        }
コード例 #5
0
 public CacheIdentify DistributedCacheSyncIdentify(CacheIdentify cacheId)
 {
     return(DistributedCacheManage.CompareCache(cacheId));
 }