示例#1
0
        /// <summary>
        /// 批量插入,并指定是否保持自增主键
        /// </summary>
        /// <typeparam name="TItem"></typeparam>
        /// <param name="details"></param>
        /// <param name="keepIdentity"></param>
        public void BatchInsert <TItem>(List <TItem> details, bool keepIdentity = false) where TItem : IModel, new()
        {
            CheckTableCreated <TItem>();
            if (details.Count == 0)
            {
                return;
            }
            foreach (TItem item in details)
            {
                CheckData(item);
            }
            _DBAdapter.BatchInsert(helper, details, keepIdentity);
            //var type = typeof(TItem);
            //if (TypeCache.ModelKeyCache.ContainsKey(type))
            //{
            //    string key = TypeCache.ModelKeyCache[type];
            //    foreach (var item in details)
            //    {
            //        MemoryDataCache.UpdateCacheItem(key, item);
            //    }
            //}
            var updateModel = MemoryDataCache.GetCacheTypeKey(typeof(TItem));

            foreach (var item in details)
            {
                foreach (var key in updateModel)
                {
                    MemoryDataCache.UpdateCacheItem(key, item, null);
                }
            }
        }
示例#2
0
        /// <summary>
        /// 更新缓存中的一项
        /// </summary>
        /// <typeparam name="TItem"></typeparam>
        /// <param name="newObj"></param>
        /// <param name="c"></param>
        internal void UpdateCacheItem <TItem>(TItem newObj, ParameCollection c) where TItem : IModel
        {
            var updateModel = MemoryDataCache.GetCacheTypeKey(typeof(TItem));

            foreach (var key in updateModel)
            {
                MemoryDataCache.UpdateCacheItem(key, newObj, c);
            }
            NotifyCacheServer(newObj);
            //Type type = typeof(TItem);
            //if (TypeCache.ModelKeyCache.ContainsKey(type))
            //{
            //    string key = TypeCache.ModelKeyCache[type];
            //    MemoryDataCache.UpdateCacheItem(key,newObj);
            //}
        }
示例#3
0
 /// <summary>
 /// 查询命令处理
 /// </summary>
 /// <param name="command"></param>
 /// <returns></returns>
 public CacheServer.ResultData DeaCacheCommand(CacheServer.Command command)
 {
     if (command.CommandType == CacheServer.CommandType.查询)
     {
         var expression = LambdaQuery.CRLQueryExpression.FromJson(command.Data);
         return(QueryFromAllCache(expression));
     }
     else
     {
         //更新缓存
         var item        = (TModel)CoreHelper.SerializeHelper.SerializerFromJSON(command.Data, typeof(TModel), Encoding.UTF8);
         var updateModel = MemoryDataCache.GetCacheTypeKey(typeof(TModel));
         foreach (var key in updateModel)
         {
             MemoryDataCache.UpdateCacheItem(key, item, null);
         }
         return(new CacheServer.ResultData());
     }
 }
示例#4
0
        /// <summary>
        /// 按表达式更新缓存中项
        /// 当前类型有缓存时才会进行查询
        /// </summary>
        /// <typeparam name="TItem"></typeparam>
        /// <param name="expression"></param>
        void UpdateCacheItem <TItem>(Expression <Func <TItem, bool> > expression, ParameCollection c) where TItem : IModel, new()
        {
            //事务开启不执行查询
            if (currentTranStatus == TranStatus.已开始)
            {
                return;
            }
            Type type        = typeof(TItem);
            var  updateModel = MemoryDataCache.GetCacheTypeKey(typeof(TItem));

            foreach (var key in updateModel)
            {
                var list = QueryList <TItem>(expression);
                foreach (var item in list)
                {
                    MemoryDataCache.UpdateCacheItem(key, item, c);
                    NotifyCacheServer(item);
                }
            }
        }