Connection pooling

In the previous version of the sdk I had to write a helper singleton class to keep alive connections to the cluster bucket. In the new sdk is this still necessary?

@envitraux -

There is a singleton cluster object that comes with the SDK

Note that you open multiple buckets (by name) using it and it will manage the resources for you.

In an ASP.NET application, you can use it like this:

 public class MvcApplication : System.Web.HttpApplication
    protected void Application_Start()

        //initialize the clusterhelper

    protected void Application_End()
        //close it down

In your controller you just get and use the bucket (but don’t dispose of it):

    public async Task<ActionResult> Index()
        var bucket = ClusterHelper.GetBucket("default");
        var result = await bucket.ExistsAsync("1000").ConfigureAwait(false);
        return View();

You just keep reusing the bucket instance, of which a reference is stored within the ClusterHelper.


Here is a snippet showing how to configure the ClusterHelper:

Thanks. I have already configured a singleton class for my connection pooling from the last version of the SDK. In the near future I will migrate.

If you need inspiration to implement the Singleton class for ClusterHelper or would like to tweak it a bit you can find the source here:

One thing to notice is the call to Dispose of bucket’s just after they are removed from the internal bucket’s list.