protected override void Dispose(bool disposing)
        {
            cluster?.Dispose();
            cluster = null;

            base.Dispose(disposing);
        }
        protected override IMemcachedCluster GetCluster()
        {
            lock (initLock)
            {
                if (cluster == null)
                {
                    cluster = NewCluster(Servers);
                }

                return(cluster);
            }
        }
예제 #3
0
        protected override IMemcachedCluster GetCluster()
        {
            lock (clusterLock)
            {
                if (sharedCluster == null)
                {
                    sharedServers = Servers;
                    sharedCluster = NewCluster(Servers);
                }

                sharedRefCount++;

                return(sharedCluster);
            }
        }
예제 #4
0
        public MemcachedClient(IMemcachedCluster cluster, IMemcachedClientOptions?options = null)
        {
            this.cluster = cluster ?? throw new ArgumentNullException(nameof(cluster));
            if (!cluster.IsStarted)
            {
                throw new ArgumentException("Cluster must be started before creating client instances", nameof(cluster));
            }

            this.allocator = cluster.Allocator;

            if (options == null)
            {
                options = new MemcachedClientOptions();
            }
            keyFormatter  = options.KeyFormatter ?? throw PropertyCannotBeNull(nameof(options.KeyFormatter));
            itemFormatter = options.ItemFormatter ?? throw PropertyCannotBeNull(nameof(options.ItemFormatter));
        }
예제 #5
0
        protected override void Dispose(bool disposing)
        {
            lock (clusterLock)
            {
                if (sharedRefCount > 0)
                {
                    Debug.Assert(sharedCluster != null);

                    sharedRefCount--;

                    if (sharedRefCount == 0)
                    {
                        sharedCluster?.Dispose();
                        sharedCluster = null;

                        sharedServers.Dispose();
                    }
                }
            }
        }
예제 #6
0
 protected static MemcachedClient NewClient(IMemcachedCluster cluster)
 => new MemcachedClient(cluster);