Exemplo n.º 1
0
        protected IRemoveOperationResult PerformRemove(string key, ulong cas = 0)
        {
            var hashedKey = this.keyTransformer.Transform(key);
            var node      = this.pool.Locate(hashedKey);
            var result    = RemoveOperationResultFactory.Create();

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

                if (commandResult.Success)
                {
                    result.Pass();
                }
                else
                {
                    commandResult.Combine(result);
                }

                return(result);
            }

            result.Fail("Unable to locate node");
            result.StatusCode = StatusCode.UnableToLocateNode.ToInt();
            return(result);
        }
        /// <summary>
        /// Removes the specified item from the cache.
        /// </summary>
        /// <param name="key">The identifier for the item to delete.</param>
        /// <returns>true if the item was successfully removed from the cache; false otherwise.</returns>
        public IRemoveOperationResult ExecuteRemove(string key)
        {
            var hashedKey = this.keyTransformer.Transform(key);
            var node      = this.pool.Locate(hashedKey);
            var result    = RemoveOperationResultFactory.Create();

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

                if (commandResult.Success)
                {
                    result.Pass();
                }
                else
                {
                    result.InnerResult = commandResult;
                    result.Fail("Failed to remove item, see InnerResult or StatusCode for details");
                }

                return(result);
            }

            result.Fail("Unable to locate node");
            return(result);
        }
        public async Task <IRemoveOperationResult> ExecuteRemoveAsync(string key)
        {
            var node   = this.pool.Locate(key);
            var result = RemoveOperationResultFactory.Create();

            if (node != null)
            {
                var command       = this.pool.OperationFactory.Delete(key, 0);
                var commandResult = await node.ExecuteAsync(command);

                if (commandResult.Success)
                {
                    result.Pass();
                }
                else
                {
                    result.InnerResult = commandResult;
                    result.Fail("Failed to remove item, see InnerResult or StatusCode for details");
                }

                return(result);
            }

            result.Fail("Unable to locate memcached node");
            return(result);
        }