미분류

Introducing the Couchbase ASP.NET OutputCache Provider

3 분 읽기

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:

<section 이름=“카우치베이스” 유형=“Couchbase.Configuration.CouchbaseClientSection, Couchbase”/>

<couchbase<
<servers 양동이=“default” bucketPassword=“”<
<add uri=“https://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” section=“couchbase-caching”/>
<
<<<outputCache defaultProvider=“CouchbaseCache”<
<providers<
<add 이름=“CouchbaseCache” 유형=“Couchbase.AspNet.OutputCache.CouchbaseOutputCacheProvider, Couchbase.AspNet” section=“couchbase-caching”/>
<
<

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

[OutputCache(Duration = 60, VaryByParam=“foo”)]
공공의 ActionResult Time(문자열 foo)
{
반환 Content(DateTime.Now.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:

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

<couchbaseSession<
<servers 양동이=“sessionState” bucketPassword=“”<
<add uri=“https://127.0.0.1:8091/pools”/>
<
<

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

<couchbaseSession<
<servers 양동이=“sessionState” bucketPassword=“”<
<add uri=“https://127.0.0.1:8091/pools”/>
<
<

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

You’re free to use the code or the 누에겟 패키지.  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!

이 기사 공유하기

작가

John Zablocki is a NET. SDK Developer at Couchbase. John is also the organizer of Beantown ALT.NET and a former adjunct at Fairfield University. You can also check out the book on Amazon named “Couchbase Essentials” which explains how to install and configure Couchbase Server.

2개의 응답

  1. jafri 아바타
    jafri

    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

댓글 남기기

카우치베이스 카펠라를 시작할 준비가 되셨나요?

개발 시작하기

NoSQL을 탐색하고, 리소스를 찾아보고, 튜토리얼을 시작하려면 개발자 포털을 확인하세요.

카펠라 프리 사용하기

단 몇 번의 클릭으로 카우치베이스(Couchbase)를 직접 체험해 보세요. Capella DBaaS는 시작하기 가장 쉽고 빠른 방법입니다.

연락해

Couchbase 제품군에 대해 더 알고 싶으신가요? 저희가 도와드리겠습니다.