/// <summary>
        /// Retrieves the specified item from the cache.
        /// </summary>
        /// <param name="key">The identifier for the item to retrieve.</param>
        /// <returns>The retrieved item, or <value>default(T)</value> if the key was not found.</returns>
        public IGetOperationResult <T> ExecuteGet <T>(string key)
        {
            object tmp;
            var    result = new DefaultGetOperationResultFactory <T>().Create();

            var tryGetResult = ExecuteTryGet(key, out tmp);

            if (tryGetResult.Success)
            {
                if (tryGetResult.Value is T)
                {
                    //HACK: this isn't optimal
                    tryGetResult.Copy(result);

                    result.Value = (T)tmp;
                    result.Cas   = tryGetResult.Cas;
                }
                else
                {
                    result.Value = default(T);
                    result.Fail("Type mismatch", new InvalidCastException());
                }
                return(result);
            }
            result.Fail("Get failed. See InnerException or StatusCode for details");
            return(result);
        }
Beispiel #2
0
        public IGetOperationResult <T> ExecuteGetWithLock <T>(string key, TimeSpan lockExpiration)
        {
            CasResult <object> tmp;
            var retVal = new DefaultGetOperationResultFactory <T>().Create();

            var result = TryGetWithLock(key, lockExpiration, out tmp);

            if (result.Success)
            {
                if (result.Value is T)
                {
                    result.Copy(retVal);
                    retVal.Value = (T)tmp.Result;
                    retVal.Cas   = result.Cas;
                }
                else
                {
                    retVal.Value = default(T);
                    retVal.Fail("Type mismatch", new InvalidCastException());
                }
                return(retVal);
            }
            retVal.InnerResult = result;
            retVal.Fail(result.Message);
            return(retVal);
        }