InfoQ

News

Using memcached with ASP.NET

Posted by Jonathan Allen on Jul 12, 2007 04:13 PM

Community
.NET
Topics
Clustering & Caching
Tags
Memcache

Instead of ASP.Net's built-in caching, some .NET developers are turning to memcached, is a distributed memory caching system originally by Danga Interactive for LiveJournal.

A fundamental problem with caching is stale data. When running a single web server, one can easily clear a cache when data is known to have been changed. Unfortunately, ASP.NET doesn't have a good way to scale this up multiple servers. Each server's cache is blissfully unaware of changes to other caches.

ASP.NET does allow triggers based on changes to the file system or a database table to invalidate a cache. However these have problems, such as the expensive polling that database triggers cause and the tedious wiring of the triggers themselves. There are other options however.

Unlike ASP.NET's built-in caching, memcached is a distributed cache. Any web server in can update or delete a cache entry and all the other servers automatically see the change next time they access the cache. This is done by storing the entries on one or more cache servers. Each entry assigned to a server based on a hash of its key.

Superficially, the ASP.NET API for memcached looks almost identical to the built-in API. This allows switching to memcached to be as easy as a single pass with search and replace.

Moving beyond just getting it running however, there are some questions as its proper use in larger web farms. Richard Jones writes

As we add more nodes, the usefulness of get_multi decreases - it's possible for a single page to hit almost all of the memcached instances. I read somewhere that facebook partition their memcached cluster to improve get_multi performance (eg, all user data on a subset of mc nodes). Can anyone comment on the effectiveness of this?

One proposed solution is to generate hash keys separately from the cache entire's key. This would allow a developer to ensure that all entries needed by a given page are more likely to be on the same server. Unfortunately, generating hash keys based on where one wants the data stored rather than from the cache key itself is likely to be error prone and will take careful implementation.

You can download memcached under a BSD license. Client APIs for C#, as well as Perl, Python, PHP, Java, and a host of other languages have to installed separately. Finally, there is a Win32 port for those not wanting to run Linux machines.

 

Great Stuff by Aaron Erickson Posted Jul 13, 2007 12:56 PM
Re: Great Stuff by Nati Shalom Posted Jul 16, 2007 10:15 AM
Coherence by Cameron Purdy Posted Jul 16, 2007 12:51 PM
Re: CSQL Cache by kanchana p Posted Jun 7, 2008 12:05 AM
  1. Back to top

    Great Stuff

    Jul 13, 2007 12:56 PM by Aaron Erickson

    I am actually doing some work on a side project that could very much use this! Thanks for the story.

  2. Back to top

    Re: Great Stuff

    Jul 16, 2007 10:15 AM by Nati Shalom

    You can find similar and much more enhanced implementation of caching solution A.K.A DataGrid through GigaSpaces It comes with built-in partitioning, SLA driven container, support for Spring, SQL query support etc. A totally free community edition is also available which support basic hub/spoke clustering, persistencey etc. And there is a .net implementation available as well. HTH Nati S. GigaSpaces write once scale anywhere

  3. Back to top

    Coherence

    Jul 16, 2007 12:51 PM by Cameron Purdy

    We've been seeing a good number of migrations recently from Memcached to Coherence lately. In addition to the support model, the main reason seems to be the issues with the "opaqueness" of using Memcached, plus necessary features such as reliable write-behind, which are necessary for high performance database integration. Peace, Cameron Purdy Oracle Coherence: Data Grid

  4. Back to top

    Re: CSQL Cache

    Jun 7, 2008 12:05 AM by kanchana p

    If you are looking for an open source alternative, CSQL Cache is the answer. It support bi-directional, updateable, real time table caching for applications. Check out this blog for its functionalites, http://csqlcache.wordpress.com Project Page: http://sourceforge.net/projects/csql

Educational Content

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.