/// <summary> /// Get entity from redis, but not surported mutil key of entity. /// </summary> /// <param name="personalId"></param> /// <param name="types"></param> /// <returns></returns> public static object[] Load(string personalId, params Type[] types) { personalId = AbstractEntity.EncodeKeyCode(personalId); var param = types.Where(t => !CacheFactory.ContainEntityKey(t, personalId)).ToArray(); if (param.Length == 0) { return(null); } var result = RedisConnectionPool.GetAllEntity(personalId, param); foreach (var t in result) { var entity = t as AbstractEntity; if (entity == null) { continue; } CacheItemSet itemSet; if (CacheFactory.AddOrUpdateEntity(entity, out itemSet)) { itemSet.OnLoadSuccess(); } } return(result); }
/// <summary> /// /// </summary> /// <param name="enumerable"></param> /// <param name="period"></param> public static bool AddRange(IEnumerable <ShareEntity> enumerable, int period = 0) { if (DataSyncQueueManager.SendSync(enumerable)) { foreach (var t in enumerable) { CacheItemSet itemSet; if (CacheFactory.AddOrUpdateEntity(t, out itemSet, period)) { itemSet.OnLoadSuccess(); } } return(true); } return(false); }
/// <summary> /// /// </summary> /// <param name="entity"></param> /// <returns></returns> public static void TransSend(AbstractEntity entity) { entity.TempTimeModify = MathUtils.Now; string key = GetQueueFormatKey(entity); if (!entity.IsInCache) { CacheFactory.AddOrUpdateEntity(key, entity); } if (_entitySet.Add(key)) { SendWaitCount++; } if (entity.IsDelete) { _entityRemoteSet.Add(key); } }
/// <summary> /// /// </summary> /// <param name="entity"></param> /// <returns></returns> public static void TransSend(AbstractEntity entity) { //watch post entity changed times. ProfileManager.PostEntityOfMessageQueueTimes(entity.GetType().FullName, entity.GetKeyCode(), GetOperateMode(entity)); entity.TempTimeModify = MathUtils.Now; string key = GetQueueFormatKey(entity); if (!entity.IsInCache) { CacheFactory.AddOrUpdateEntity(key, entity); } lock (entitySyncRoot) { _entitySet.Add(key); if (entity.IsDelete) { _entityRemoteSet.Add(key); } } }
/// <summary> /// /// </summary> /// <param name="checkMutilKey">The entity need to reload when it has be mutil key</param> /// <param name="enumerable"></param> public static bool AddRange(bool checkMutilKey, params BaseEntity[] enumerable) { if (DataSyncQueueManager.SendSync(enumerable)) { foreach (var t in enumerable) { var schema = t.GetSchema(); CacheItemSet itemSet; if (CacheFactory.AddOrUpdateEntity(t, out itemSet)) { if (checkMutilKey && schema.Keys.Length > 1 && !itemSet.HasLoadSuccess) { ReLoad(t.PersonalId, schema); } else { itemSet.OnLoadSuccess(); } } } return(true); } return(false); }
private IEnumerable <T> GetMutilCacheItem(IEnumerable <string> keys, bool isAutoLoad) { CheckLoad(); //保证返回顺序 var result = new List <T>(); var loadKey = new List <string>(); var indexList = new Queue <int>(); foreach (var key in keys) { CacheItemSet itemSet; if (isAutoLoad && Container.TryGetValue(key, out itemSet) && itemSet.HasLoadSuccess) { var itemData = itemSet.GetItem(); var collection = itemData as BaseCollection; if (collection == null) { result.Add((T)itemData); } else { result.AddRange(collection.Select(pair => (T)pair.Value)); } } else { loadKey.Add(key); indexList.Enqueue(result.Count); result.Add(null); } } if (loadKey.Count == 0) { return(result); } var enumratable = RedisConnectionPool.GetAllEntity <T>(loadKey); foreach (var t in enumratable) { var entity = t as AbstractEntity; if (entity == null) { continue; } CacheItemSet itemSet; if (CacheFactory.AddOrUpdateEntity(entity, out itemSet)) { itemSet.OnLoadSuccess(); } int index = indexList.Count > 0 ? indexList.Dequeue() : -1; if (index == -1) { result.Add(t); } else { result[index] = t; } } return(result); }