Beispiel #1
0
        protected override IGetOperationResult PerformTryGet(string key, out ulong cas, out object value)
        {
            var hashedKey = this.KeyTransformer.Transform(key);
            var node      = this.Pool.Locate(hashedKey);
            var result    = GetOperationResultFactory.Create();

            if (node != null)
            {
                var command = this.Pool.OperationFactory.Get(hashedKey);

                var executeResult = ExecuteWithRedirect(node, command);
                if (executeResult.Success)
                {
                    result.Value = value = this.Transcoder.Deserialize(command.Result);
                    result.Cas   = cas = command.CasValue;
                    if (this.PerformanceMonitor != null)
                    {
                        this.PerformanceMonitor.Get(1, true);
                    }

                    result.Pass();
                    return(result);
                }
            }

            value = null;
            cas   = 0;
            if (this.PerformanceMonitor != null)
            {
                this.PerformanceMonitor.Get(1, false);
            }

            result.Fail("Unable to locate node");
            return(result);
        }
 /// <summary>
 /// Retrieves multiple items from the cache.
 /// </summary>
 /// <param name="keys">The list of identifiers for the items to retrieve.</param>
 /// <returns>a Dictionary holding all items indexed by their key.</returns>
 public IDictionary <string, IGetOperationResult> ExecuteGet(IEnumerable <string> keys)
 {
     return(PerformMultiGet <IGetOperationResult>(keys, (mget, kvp) =>
     {
         var result = GetOperationResultFactory.Create();
         result.Value = this.transcoder.Deserialize(kvp.Value);
         result.Cas = mget.Cas[kvp.Key];
         result.Success = true;
         return result;
     }));
 }
Beispiel #3
0
        protected IGetOperationResult PerformTryGetWithLock(string key, TimeSpan lockExpiration, out ulong cas, out object value)
        {
            var hashedKey = this.KeyTransformer.Transform(key);
            var node      = this.Pool.Locate(hashedKey);
            var result    = GetOperationResultFactory.Create();
            var exp       = (uint)lockExpiration.Seconds;

            if (exp > 30)
            {
                throw new ArgumentOutOfRangeException("Timeout cannot be greater than 30 seconds");
            }

            if (node != null)
            {
                var command       = this.poolInstance.OperationFactory.GetWithLock(hashedKey, exp);
                var commandResult = this.ExecuteWithRedirect(node, command);

                if (commandResult.Success)
                {
                    result.Value = value = this.Transcoder.Deserialize(command.Result);
                    result.Cas   = cas = command.CasValue;
                    if (this.PerformanceMonitor != null)
                    {
                        this.PerformanceMonitor.Get(1, true);
                    }

                    result.Pass();
                    return(result);
                }
                else
                {
                    commandResult.Combine(result);
                    value = null;
                    cas   = 0;
                    return(result);
                }
            }

            value = null;
            cas   = 0;
            if (this.PerformanceMonitor != null)
            {
                this.PerformanceMonitor.Get(1, false);
            }

            result.Fail(ClientErrors.FAILURE_NODE_NOT_FOUND);
            return(result);
        }
Beispiel #4
0
        protected IGetOperationResult PerformTryGetAndTouch(string key, uint nextExpiration, out ulong cas, out object value)
        {
            var hashedKey = this.KeyTransformer.Transform(key);
            var node      = this.Pool.Locate(hashedKey);
            var result    = GetOperationResultFactory.Create();

            if (node != null)
            {
                var command       = this.poolInstance.OperationFactory.GetAndTouch(hashedKey, nextExpiration);
                var commandResult = this.ExecuteWithRedirect(node, command);

                if (commandResult.Success)
                {
                    result.Value = value = this.Transcoder.Deserialize(command.Result);
                    result.Cas   = cas = command.CasValue;
                    if (this.PerformanceMonitor != null)
                    {
                        this.PerformanceMonitor.Get(1, true);
                    }

                    result.Pass();
                    return(result);
                }
                else
                {
                    cas   = 0;
                    value = null;
                    result.InnerResult = commandResult;
                    result.Fail("Failed to execute Get and Touch operation, see InnerException or StatusCode for details");
                }
            }

            value = null;
            cas   = 0;
            if (this.PerformanceMonitor != null)
            {
                this.PerformanceMonitor.Get(1, false);
            }

            result.Fail(ClientErrors.FAILURE_NODE_NOT_FOUND);
            return(result);
        }
Beispiel #5
0
		protected virtual IGetOperationResult PerformTryGet(string key, out ulong cas, out object value)
		{
			var hashedKey = this.keyTransformer.Transform(key);
			var node = this.pool.Locate(hashedKey);
			var result = GetOperationResultFactory.Create();

			cas = 0;
			value = null;

			if (node != null)
			{
				var command = this.pool.OperationFactory.Get(hashedKey);
				var commandResult = node.Execute(command);

				if (commandResult.Success)
				{
					result.Value = value = this.transcoder.Deserialize(command.Result);
					result.Cas = cas = command.CasValue;

					if (this.performanceMonitor != null) this.performanceMonitor.Get(1, true);

					result.Pass();
					return result;
				}
				else
				{
					commandResult.Combine(result);
					return result;
				}
			}

			result.Value = value;
			result.Cas = cas;

			if (this.performanceMonitor != null) this.performanceMonitor.Get(1, false);

			result.Fail("Unable to locate node");
			return result;
		}
Beispiel #6
0
 /// <summary>
 /// Retrieves multiple items from the cache.
 /// </summary>
 /// <param name="keys">The list of identifiers for the items to retrieve.</param>
 /// <returns>a Dictionary holding all items indexed by their key.</returns>
 public IDictionary <string, IGetOperationResult> ExecuteGet(IEnumerable <string> keys)
 {
     return(PerformMultiGet <IGetOperationResult>(
                keys,
                (mget, kvp) =>
     {
         var result = GetOperationResultFactory.Create();
         result.Value = this.transcoder.Deserialize(kvp.Value);
         result.Cas = mget.Cas[kvp.Key];
         result.Success = true;
         result.StatusCode = StatusCode.Success.ToInt();
         return result;
     },
                opResult =>
     {
         var result = GetOperationResultFactory.Create();
         result.Success = false;
         result.StatusCode = opResult.StatusCode;
         result.Message = opResult.Message;
         result.Exception = opResult.Exception;
         return result;
     }));
 }