示例#1
0
        protected override CommandBase GetMergedCommand(List <CommandBase> commands)
        {
            BulkAddCommand mergedCommand = null;

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

            return(mergedCommand);
        }
示例#2
0
        /// <summary>
        /// Add array 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>keys that are added or that alredy exists in the cache 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 add items to the cache with an absolute 
        /// expiration 2 minutes from now, a priority of 
        /// high, and that notifies the application when the item is removed from the cache.
        /// 
        /// First create a CacheItems.
        /// <code>
        /// string keys = {"ORD_23", "ORD_67"};
        /// CacheItem items = new CacheItem[2]
        /// items[0] = new CacheItem(new Order());
        /// items[0].AbsoluteExpiration = DateTime.Now.AddMinutes(2);
        /// items[0].Priority = CacheItemPriority.High;
        /// items[0].ItemRemoveCallback = onRemove;
        ///
        /// items[1] = new CacheItem(new Order());
        /// items[1].AbsoluteExpiration = DateTime.Now.AddMinutes(2);
        /// items[1].Priority = CacheItemPriority.Low;
        /// items[1].ItemRemoveCallback = onRemove;
        /// </code>
        /// 
        /// Then add CacheItem to the cache
        /// <code>
        /// 
        ///	NCache.Cache.Add(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.Add(keys, items);
        /// 
        /// </code>
        /// </example>
        public override IDictionary Add(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)
                {
                    BulkAddCommand command = new BulkAddCommand(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];
                        BulkAddCommand command = new BulkAddCommand(keysAndItems.Key, keysAndItems.Value, _parent, CacheId);
                        command.ClientLastViewId = _broker.ClientLastViewId;
                        request.AddCommand(serverAddress, command);
                    }
                }
            }
            else
            {
                BulkAddCommand command = new BulkAddCommand(keys, items,  _parent, CacheId);
                request = _broker.CreateRequest(command);
            }

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

            return res.KeyValueDic;
        }