コード例 #1
0
ファイル: EntityContainer.cs プロジェクト: longshenwudu/TNet4
        /// <summary>
        ///
        /// </summary>
        /// <param name="groupKey"></param>
        /// <param name="key"></param>
        /// <param name="entityData"></param>
        /// <param name="periodTime"></param>
        /// <param name="isLoad"></param>
        /// <returns></returns>
        public bool TryAddGroup(string groupKey, string key, T entityData, int periodTime, bool isLoad = false)
        {
            CacheItemSet itemSet = InitGroupContainer(groupKey, periodTime);

            if (itemSet != null)
            {
                if (!Equals(entityData, default(T)) && ((BaseCollection)itemSet.GetItem()).TryAdd(key, entityData))
                {
                    CheckEventBind(entityData as AbstractEntity);
                    if (!isLoad)
                    {
                        entityData.TriggerNotify();
                    }
                    entityData.IsInCache = true;
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
ファイル: EntityContainer.cs プロジェクト: longshenwudu/TNet4
        /// <summary>
        ///
        /// </summary>
        /// <param name="groupKey"></param>
        /// <param name="key"></param>
        /// <param name="entityData"></param>
        /// <param name="periodTime"></param>
        /// <param name="isLoad"></param>
        /// <returns></returns>
        public bool AddOrUpdateGroup(string groupKey, string key, T entityData, int periodTime, bool isLoad = false)
        {
            bool         result  = false;
            CacheItemSet itemSet = InitGroupContainer(groupKey, periodTime);

            if (itemSet != null && !Equals(entityData, default(T)))
            {
                var data = (BaseCollection)itemSet.GetItem();
                result = data.AddOrUpdate(key, entityData, (k, t) => entityData) == entityData;
                if (result)
                {
                    var temp = entityData as AbstractEntity;
                    CheckEventBind(temp);
                    if (!isLoad)
                    {
                        entityData.TriggerNotify();
                    }
                    entityData.IsInCache = true;
                }
            }
            return(result);
        }