Click here to Skip to main content
13,406,177 members (50,160 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 18 Apr 2011

Using Membase for ASP.NET Output Caching

, 18 Apr 2011
Rate this:
Please Sign up or sign in to vote.
Using Membase for ASP.NET Output Caching

Membase is no-SQL, distributed, key-value database management system for storing data offered by NorthScale.

Download and Installation of Membase

Membase community edition can be downloaded from here. Its installation is pretty straightforward.

Membase Client

Membase has client support available in C# and the client support libraries can be downloaded from here.

ASP.NET Project

Create a new Visual Studio ASP.NET Web Application. Add Membase.dll and Enyim.Caching.dll as references to the project.

Initializing Membase from Website

Open web.config for the application and the following section under configSections:


Change the URI to point to your Membase server. If you are having a clustered environment, add multiple (Check Membase demo sample). Next step would be to initialize the connection between the Membase and website. Open Global.asax file and add the following code block at Application Start event.


Note: Unity Framework is used to manage the lifetime of MembaseClient object.

MembaseOuptputCacheProvider: Extension Class for Output Cache

In .NET Framework 4.0, Microsoft provided us the ability to extend the Output Cache and use our own custom Output Cache mechanism for the application. To implement a new OutputCache provider, we need to implement OutputCacheProvider class. This class defines four abstract methods:

  • Add: key, object value and expiry time is passed to the method. However if the key already exists in the cache, one has to return the value associated with it (imp).
  • Get: It returns the object associated with the key.
  • Remove: Remove the key associated from the cache.
  • Set: Add/Update the key in cache, and its expiry.

Following is the implementation for the class:


The above is the implementation for subclass MembaseCacheProvider. The constructor uses the Unity Framework to get a reference to the MembaseClient.

The Add method does a look up for the key. If the key is found in Membase, it returns the value associated, else the value is stored in Membase for the given expiry time. Membase provides Store method for saving/updating the items in cache. To Add a new key to Membase, StoreMode.Add is passed to method.

The Get method does a look up for the key. If the key is not found in the cache, it returns null.

The Remove method calls the remove method of Membase client and removes the value from the key.

The Set method does a look up for the key. If the item is found in store, it does the update for item, else it Adds it as new item.

Setting Custom Provider as Default

In web.config file, add the following section under System.web:


This block of code tells .NET to register the Custom Output Cache as the default cache mechanism for the application.

Last Step: Testing

To test, I would do the basic output cache based on param. Let's create a page and the following Output Cache Directive on the top of page.

<%@ OutputCache VaryByParam="Test" Duration="60000? %>

And add the following block in the Code behind:


Run the application and we can see the caching works fine.

If we check the Membase console and take a look at the top keys for default bucket, we will see the entries done by .NET Framework.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer SAP Labs
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180221.1 | Last Updated 18 Apr 2011
Article Copyright 2011 by andy404
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid