/// <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);
        }
Beispiel #3
0
        public Task <IGetOperationResult> GetAsync(string key)
        {
            var result = new DefaultGetOperationResultFactory().Create();

            result.Success = false;
            return(Task.FromResult(result));
        }
Beispiel #4
0
        public async Task <IGetOperationResult <T> > GetAsync <T>(string key)
        {
            var result = new DefaultGetOperationResultFactory <T>().Create();

            result.Success = false;
            result.Value   = default(T);
            return(await Task.FromResult(result));
        }
Beispiel #5
0
        protected CouchbaseClient(ICouchbaseServerPool pool, ICouchbaseClientConfiguration configuration)
            : base(pool,
                   configuration.CreateKeyTransformer(),
                   configuration.CreateTranscoder(),
                   configuration.CreatePerformanceMonitor())
        {
            this.documentNameTransformer = configuration.CreateDesignDocumentNameTransformer();
            this.poolInstance            = (ICouchbaseServerPool)this.Pool;
            observeTimeout = configuration.ObserveTimeout;

            StoreOperationResultFactory  = new DefaultStoreOperationResultFactory();
            GetOperationResultFactory    = new DefaultGetOperationResultFactory();
            MutateOperationResultFactory = new DefaultMutateOperationResultFactory();
            ConcatOperationResultFactory = new DefaultConcatOperationResultFactory();
            RemoveOperationResultFactory = new DefaultRemoveOperationResultFactory();
        }
Beispiel #6
0
		/// <summary>
		/// Initializes a new instance of the <see cref="T:MemcachedClient"/> using the specified configuration instance.
		/// </summary>
		/// <param name="configuration">The client configuration.</param>
		public MemcachedClient(IMemcachedClientConfiguration configuration)
		{
			if (configuration == null)
				throw new ArgumentNullException("configuration");

			this.keyTransformer = configuration.CreateKeyTransformer() ?? new DefaultKeyTransformer();
			this.transcoder = configuration.CreateTranscoder() ?? new DefaultTranscoder();
			this.performanceMonitor = configuration.CreatePerformanceMonitor();

			this.pool = configuration.CreatePool();
			this.pool.NodeFailed += (n) => { var f = this.NodeFailed; if (f != null) f(n); };
			this.StartPool();

			StoreOperationResultFactory = new DefaultStoreOperationResultFactory();
			GetOperationResultFactory = new DefaultGetOperationResultFactory();
			MutateOperationResultFactory = new DefaultMutateOperationResultFactory();
			ConcatOperationResultFactory = new DefaultConcatOperationResultFactory();
			RemoveOperationResultFactory = new DefaultRemoveOperationResultFactory();
		}