This library provides infrastructure support for using Couchbase Server and ASP.NET.
ASP.NET SessionState Provider
- Port of the Enyim Memcached Provider to Couchbase Server
- You'll need .NET Framework 3.5 or later to use the precompiled binaries.
- To build the client, you'll need Visual Studio 2010 with MVC 3 installed.
- The Nuget package for CouchbaseNetClient 1.0.6 is referenced by Couchbase.AspNet
- Couchbase Server 1.8
Update the sessionState section in Web.config as follows:
<sessionState customProvider="Couchbase" mode="Custom">
<providers>
<add name="Couchbase" type="Couchbase.AspNet.SessionState.CouchbaseSessionStateProvider, Couchbase.AspNet" />
</providers>
</sessionState>
Configure the Couchbase Client as you normally would:
<section name="couchbase" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
<couchbase>
<servers bucket="default" bucketPassword="">
<add uri="http://127.0.0.1:8091/pools"/>
</servers>
</couchbase>
If you would like to use a custom configuration section, you may do so by specifying a value for the "section" attribute of the provider entry (see below).
<section name="couchbaseSession" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
<couchbaseSession>
<servers bucket="sessionState" bucketPassword="">
<add uri="http://127.0.0.1:8091/pools"/>
</servers>
</couchbaseSession>
<sessionState customProvider="Couchbase" mode="Custom">
<providers>
<add name="Couchbase" type="Couchbase.AspNet.SessionState.CouchbaseSessionStateProvider, Couchbase.AspNet" section="couchbaseSession" />
</providers>
</sessionState>
Note that currently, code-based configuration of the CouchbaseClient is not supported.
In code, simply use the Session object as you normally would.
Session["Message"] = "Couchbase is awesome!";
Be sure to mark any user defined types as Serializable.
[Serializable]
public class SessionUser
{
public string Username { get; set; }
public string Email { get; set; }
}
Update the outputCache section in Web.config as follows:
<outputCache defaultProvider="CouchbaseCache">
<providers>
<add name="CouchbaseCache" type="Couchbase.AspNet.OutputCache.CouchbaseOutputCacheProvider, Couchbase.AspNet" section="couchbase-caching"/>
</providers>
</outputCache>
Configure the Couchbase Client as you normally would:
<section name="couchbase" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
<couchbase>
<servers bucket="default" bucketPassword="">
<add uri="http://127.0.0.1:8091/pools"/>
</servers>
</couchbase>
If you would like to use a custom configuration section, you may do so by specifying a value for the "section" attribute of the provider entry (see below).
<section name="couchbaseSession" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
<couchbaseSession>
<servers bucket="sessionState" bucketPassword="">
<add uri="http://127.0.0.1:8091/pools"/>
</servers>
</couchbaseSession>
<outputCache defaultProvider="CouchbaseCache">
<providers>
<add name="Couchbase" type="Couchbase.AspNet.SessionState.CouchbaseSessionStateProvider, Couchbase.AspNet" section="couchbaseSession" />
</providers>
</outputCache>
Once configured, simply enable output cache as you already do with ASP.NET MVC
[OutputCache(Duration = 60, VaryByParam="foo")]
public ActionResult Time(string foo)
{
return Content(DateTime.Now.ToString());
}
or with ASP.NET WebForms
<%@ OutputCache Duration="60" VaryByParam="foo" %>