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

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

            return(mergedCommand);
        }
Beispiel #2
0
        ///  <summary>
        ///  Retrieves the object from the cache for the given keys as key value pairs
        ///  </summary>
        /// <param name="keys">The keys against which items are to be fetched.</param>
        /// <returns>The retrieved cache items.</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 to retrieve the value cached for an ASP.NET text 
        ///  box server control.
        ///  <code>
        ///  
        /// 	NCache.Cache.Get(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.Get(keys);
        ///  
        ///  </code> 
        ///  </example>
        public override IDictionary Get(string[] keys, BitSet flagMap)
        {
            Dictionary<Address, KeyValuePair<string[], CacheItem[]>> keysDistributionMap = new Dictionary<Address, KeyValuePair<string[], CacheItem[]>>();
            Request request;
            if (_broker.ImportHashmap)
            {
                if (!_broker.PoolFullyConnected)
                {
                    BulkGetCommand command = new BulkGetCommand(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];
                        BulkGetCommand command = new BulkGetCommand(keysAndItems.Key, flagMap);
                        command.ClientLastViewId = _broker.ClientLastViewId;
                        request.AddCommand(serverAddress, command);
                    }
                }
            }
            else
            {
                BulkGetCommand command = new BulkGetCommand(keys, flagMap);
                request = _broker.CreateRequest(command);
            }

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

            return res.KeyValueDic;
        }