Hello,
The .NET SDK 2.0 documentation clearly states that the ICluster
object is thread safe and a single instance should be reused across the entire application. On the other hand the Java SDK documentation explicitly states that both the cluster and bucket instances are thread safe and can be long lived and reused across the entire application.
Assuming that my ASP.NET application works with only one bucket, can I reuse a bucket instance?
For example in my Application_Start
I would create a singleton bucket and reuse it across my application:
public static ICluster Cluster;
public static IBucket Bucket;
protected void Application_Start(object sender, EventArgs e)
{
Cluster = new Cluster("couchbaseClients/couchbase");
string bucketName = Cluster.Configuration.BucketConfigs.Single().Key;
Bucket = cluster.OpenBucket(bucketName);
}
protected void Application_End(object sender, EventArgs e)
{
Cluster.CloseBucket(bucket);
Cluster.Dispose();
}
Initially I was opening and closing the bucket from the cluster instance for every operation I wanted to perform but I noticed that the cluster.OpenBucket
method is very slow and I thought that reusing the bucket instance would be fine. Is this a correct approach and is it how the SDK is supposed to be used?
Thanks in advance.