protected override CommandBase GetMergedCommand(List <CommandBase> commands) { BulkRemoveCommand mergedCommand = null; if (commands != null || commands.Count > 0) { foreach (CommandBase command in commands) { if (command is BulkRemoveCommand) { BulkRemoveCommand bulkCommand = (BulkRemoveCommand)command; if (mergedCommand == null) { mergedCommand = bulkCommand; } else { mergedCommand._bulkRemoveCommand.keys.AddRange(bulkCommand._bulkRemoveCommand.keys); } } } } return(mergedCommand); }
/// <summary> /// Removes the objects from the <see cref="Cache"/>. /// </summary> /// <param name="keys">The cache keys used to reference the item.</param> /// <param name="flagMap"></param> /// <returns>The items removed from the Cache. If the value in the keys parameter /// is not found, returns a null reference (Nothing in Visual Basic).</returns> /// <exception cref="ArgumentNullException"><paramref name="keys"/> contains a null reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentException"><paramref name="keys"/> is not serializable.</exception> /// <remarks> /// <para><b>Note:</b> If exceptions are enabled through the <see cref="NCache.ExceptionsEnabled"/> /// setting, this property throws exception incase of failure.</para> /// </remarks> /// <example>The following example demonstrates how you can remove an item from your application's /// <see cref="Cache"/> object. /// <code> /// /// NCache.Cache.Remove(keys); /// /// </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.Remove(keys); /// /// </code> /// </example> public override IDictionary Remove(string[] keys, BitSet flagMap) { Dictionary<Address, KeyValuePair<string[], CacheItem[]>> keysDistributionMap = new Dictionary<Address, KeyValuePair<string[], CacheItem[]>>(); Request request; if (_broker.ImportHashmap) { if (!_broker.PoolFullyConnected) { BulkRemoveCommand command = new BulkRemoveCommand(keys, flagMap); request = _broker.CreateDedicatedRequest(command); } else { request = new Request(true, _broker.OperationTimeOut); _broker.GetKeysDistributionMap(keys, null, ref keysDistributionMap); foreach (Address serverAddress in keysDistributionMap.Keys) { KeyValuePair<string[], CacheItem[]> keysAndItems = keysDistributionMap[serverAddress]; BulkRemoveCommand command = new BulkRemoveCommand(keysAndItems.Key, flagMap); command.ClientLastViewId = _broker.ClientLastViewId; request.AddCommand(serverAddress, command); } } } else { BulkRemoveCommand command = new BulkRemoveCommand(keys, flagMap); request = _broker.CreateRequest(command); } _broker.ExecuteRequest(request); CommandResponse res = request.Response; res.ParseResponse(); return res.KeyValueDic; }