As was reiterated in a recent post by A Main Hobbies CEO Kendall Bennett, Couchbase is a great solution for improving the performance of your ASP.NET applications.  Beyond offering sub-millisecond CRUD operations for your application’s persistence  needs, Couchbase also offers many benefits for your application’s transient data needs.

In addition to managing your ASP.NET session state with Couchbase Server, you can now use Couchbase Server as the backing store for your application’s output cache.  The latest commits to the Couchbase.AspNet project on Couchbase Labs includes the CouchbaseOutputCacheProvider.

A brief aside for those interested in implementation details or for those who have implemented an output cache provider…  It turns out that Couchbase Server is well suited for use as an output cache backing store.  With its time-to-live capabilities, creating the CouchbaseOutputCacheProvider class required very few lines of code.  There was no need to create a wrapper around the cache item just to add a persisted expiration field.  There was no need to check the expiration of an item after retrieving it, since it wouldn’t be returned by Couchbase Server if expired.

To use the new provider, you’ll configure the client as you always do:

<섹션 이름="couchbase" 유형=“Couchbase.Configuration.CouchbaseClientSection, Couchbase”/>

<couchbase>
<servers 버킷="default" 버킷 비밀번호=“”>
<add uri=“http://127.0.0.1:8091/pools”/>
>
>

Then configure the outputCache provider section:

<code><outputCache defaultProvider=“CouchbaseCache”>
<providers>
<add 이름=“CouchbaseCache” 유형=“Couchbase.AspNet.OutputCache.CouchbaseOutputCacheProvider, Couchbase.AspNet” 섹션=“couchbase-caching”/>
>
>><outputCache defaultProvider=“CouchbaseCache”>
<providers>
<add 이름=“CouchbaseCache” 유형=“Couchbase.AspNet.OutputCache.CouchbaseOutputCacheProvider, Couchbase.AspNet” 섹션=“couchbase-caching”/>
>
>

Then configure OutputCache on your actions as you normally would (ASP.NET MVC):

[OutputCache(기간 = 60, VaryByParam="foo")]
public ActionResult Time(문자열 foo)
{
반환 콘텐츠(날짜/시간.지금.ToString());
}

Or in ASP.NET WebForms, use the page directive:

<%@ OutputCache Duration=“60” VaryByParam="foo" %>

If you’re already using Couchbase in your app and need to specify a custom section, simply provide a new section name and set a “section” attribute on the “add” node of the “providers” element as below:

<섹션 이름=“couchbaseSession” 유형=“Couchbase.Configuration.CouchbaseClientSection, Couchbase”/>

<couchbaseSession>
<servers 버킷=“sessionState” 버킷 비밀번호=“”>
<add uri=“http://127.0.0.1:8091/pools”/>
>
>

<outputCache defaultProvider=“CouchbaseCache”>
<providers>
<add 이름=“Couchbase” 유형=“Couchbase.AspNet.SessionState.CouchbaseSessionStateProvider, Couchbase.AspNet” 섹션=“couchbaseSession” />
>
><섹션 이름=“couchbaseSession” 유형=“Couchbase.Configuration.CouchbaseClientSection, Couchbase”/>

<couchbaseSession>
<servers 버킷=“sessionState” 버킷 비밀번호=“”>
<add uri=“http://127.0.0.1:8091/pools”/>
>
>

<outputCache defaultProvider=“CouchbaseCache”>
<providers>
<add 이름=“Couchbase” 유형=“Couchbase.AspNet.SessionState.CouchbaseSessionStateProvider, Couchbase.AspNet” 섹션=“couchbaseSession” />
>
>

You’re free to use the code 또는 너겟 패키지.  This is a Couchbase Labs project with the  Apache License 2.0.  Just remember though, that this isn’t an officially supported Couchbase product.  Feel free to post questions to the forums though.

Happy output-caching!

작성자

게시자 존 자블로키, NET. SDK 개발자, Couchbase

존 자블로키는 NET. SDK 개발자입니다. John은 Beantown ALT.NET의 주최자이자 Fairfield University의 전 겸임교수이기도 합니다. Amazon에서 Couchbase Server를 설치하고 구성하는 방법을 설명하는 "Couchbase Essentials"라는 책을 확인할 수도 있습니다.

댓글 하나

  1. very comprehensive and complete article showing all aspects of this instance.

    We are normally using MVC and DOJO with ASP.NET. see examples of work and contact http://www.smallmarketingcompany.com

댓글 남기기