Exemple #1
0
        protected override CommandBase GetMergedCommand(List <CommandBase> commands)
        {
            BulkInsertCommand mergedCommand = null;

            if (commands != null || commands.Count > 0)
            {
                foreach (CommandBase command in commands)
                {
                    if (command is BulkInsertCommand)
                    {
                        BulkInsertCommand bulkCommand = (BulkInsertCommand)command;
                        if (mergedCommand == null)
                        {
                            mergedCommand = bulkCommand;
                        }
                        else
                        {
                            mergedCommand._bulkInsertCommand.insertCommand.AddRange(bulkCommand._bulkInsertCommand
                                                                                    .insertCommand);
                        }
                    }
                }
            }

            return(mergedCommand);
        }
Exemple #2
0
        ///  <summary> Insert list of <see cref="CacheItem"/> to the cache </summary>
        /// <param name="keys">The cache keys used to reference the items.</param>
        /// <param name="items">The items that are to be stored</param>
        /// <returns>returns keys that are added or updated successfully and their status.</returns>
        /// <remarks> If CacheItem contains invalid values the related exception is thrown. 
        /// See <see cref="CacheItem"/> for invalid property values and related exceptions</remarks>
        /// <example>The following example demonstrates how to assign an item high priority when you insert 
        /// it into your application's <see cref="Cache"/> object.
        ///	<para><b>Note: </b>For more information about how to use this method with the <see cref="CacheItemRemovedCallback"/> 
        ///	delegate, see <see cref="CacheItemRemovedCallback"/>.
        ///	</para>
        /// First create CacheItems.
        /// <code>
        /// string[] keys = {"SQLDSN", "ORADSN"};
        /// CacheItem items[] = new CacheItem[2];
        /// items[0] = new CacheItem(sqlConnectionString);
        /// item.AbsoluteExpiration = DateTime.Now.AddMinutes(2);
        /// item.SlidingExpiration = TimeSpan.Zero;
        /// item.Priority = CacheItemPriority.High;
        /// item.ItemRemoveCallback = onRemove;
        /// 
        /// items[1] = new CacheItem(oraConnectionString);
        /// item.AbsoluteExpiration = DateTime.Now.AddMinutes(1);
        /// item.SlidingExpiration = TimeSpan.Zero;
        /// item.Priority = CacheItemPriority.Low;
        /// item.ItemRemoveCallback = onRemove;
        /// </code>
        /// 
        /// Then insert CacheItems to the cache
        /// <code>
        ///
        ///	NCache.Cache.Insert(keys, items);
        /// 
        /// </code>
        /// Or simply in a class deriving from <see cref="Alachisoft.NCache.Web.UI.NPage"/> or <see cref="Alachisoft.NCache.Web.UI.NUserControl"/>.
        /// <code>
        /// 
        ///	Cache.Insert(keys, items);
        /// 
        /// </code>
        /// </example>
        public override IDictionary Insert(string[] keys, CacheItem[] items, long[] sizes)
        {
            Dictionary<Address, KeyValuePair<string[], CacheItem[]>> keysDistributionMap = new Dictionary<Address, KeyValuePair<string[], CacheItem[]>>();
            Request request;
            if (_broker.ImportHashmap)
            {
                if (!_broker.PoolFullyConnected)
                {
                    BulkInsertCommand command = new BulkInsertCommand(keys, items, _parent, CacheId);
                    request = _broker.CreateDedicatedRequest(command);
                }
                else
                {
                    request = new Request(true, _broker.OperationTimeOut);
                    _broker.GetKeysDistributionMap(keys, items, ref keysDistributionMap);
                    foreach (Address serverAddress in keysDistributionMap.Keys)
                    {
                        KeyValuePair<string[], CacheItem[]> keysAndItems = keysDistributionMap[serverAddress];
                        BulkInsertCommand command = new BulkInsertCommand(keysAndItems.Key, keysAndItems.Value, _parent, CacheId);
                        command.ClientLastViewId = _broker.ClientLastViewId;
                        request.AddCommand(serverAddress, command);
                    }
                }
            }
            else
            {
                BulkInsertCommand command = new BulkInsertCommand(keys, items, _parent, CacheId);
                request = _broker.CreateRequest(command);
            }

            _broker.ExecuteRequest(request);

            CommandResponse res = request.Response;
            res.ParseResponse();

            return res.KeyValueDic;
        }