Download and extract the Enyim Membase client library into a directory, and then right click on References|Add Reference in the solution explorer, select the Browse tab and navigate to where you extracted the client library. Select the Enyim.caching.dll and Membase.dll and click OK to add these references to your project. See Figure 5.
Once the references have been made, you will want to add an
instance of MemcacheClient to your project. One
of the best places to do this is in Global.asax.cs in the
Application_Start() method which is guaranteed to be run only once
during the lifetime of the application.
Add the following static instance variable to the
MvcApplication class:
public static MembaseClient MembaseClient { get; private set; }
Add the following line to the end of the
Application_Start() method:
MembaseClient = new MembaseClient();
Then add the method in Listing 4 below
Application_Start().
Listing 4: Application_End() method.
protected void Application_End() { MembaseClient.Dispose(); }
Now, in order for the MembaseClient to be created at runtime, configuration to specify the bucket and server address to connect to must be added. Edit the Web.config file and add the following XML after the opening <configuration> element:
Listing 5: Web.config
<configSections> <section name="membase" type="Membase.Configuration.MembaseClientSection, Membase"/> </configSections> <membase> <servers bucket="private" bucketPassword="private"> <add uri="http://10.0.0.33:8091/pools/default"/> </servers> </membase>
You would replace 10.0.0.33 with the address of your server, and
also set your bucket and bucketPassword
attributes appropriately.