Add the following using statements to Program.cs:
using Couchbase; using Enyim.Caching.Memcached; using Enyim.Caching.Memcached; using Newtonsoft.Json;
Couchbase is the namespace containing the client and configuration classes with which you'll work. Enyim.Caching.Memcached contains supporting infrastructure. Recall that Couchbase supports the Memcached protocol and is therefore able to make use of the popular Enyim Memcached client for many of its core key/value operations.
Next create an instance of the client in the Main method. Use the default constructor, which depends on the configuration from app.config.
var client = new CouchbaseClient();In practice, it's expensive to create clients. The client incurs overhead as it creates connection pools and sets up the thread to get cluster configuration. Therefore, the best practice is to create a single client instance, per bucket, per AppDomain. Creating a static property on a class works well for this purpose. For example:
public static class CouchbaseManager { private readonly static CouchbaseClient _instance; static CouchbaseManager() { _instance = new CouchbaseClient(); } public static CouchbaseClient Instance { get { return _instance; } } }
However, for the purpose of this getting started guide the locally scoped client variable created above is sufficient.