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); } }
protected override IMemcachedCluster GetCluster() { lock (clusterLock) { if (sharedCluster == null) { sharedServers = Servers; sharedCluster = NewCluster(Servers); } sharedRefCount++; return(sharedCluster); } }
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)); }
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(); } } } }
protected static MemcachedClient NewClient(IMemcachedCluster cluster) => new MemcachedClient(cluster);