Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <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);
        }