Migration Solutions for ColdFusion Applications to ASP.NET
      
Vince Bonfanti's Weblog

memcached client CFC for BlueDragon.NET

We were recently asked by a customer whether BlueDragon.NET could support memcached, a "high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load." Though BlueDragon.NET already supports query caching, our customer's goal is to implement a cache that can be shared across multiple servers in a cluster and that can store data types other than just query results.

In response to their request we created the Memcached client CFC for BlueDragon.NET, which is based on the .NET memcached client library.

Using the Memcached client CFC is fairly straight forward:

  1. Copy the Commons.dll, ICSharpCode.SharpZipLib.dll, log4net.dll, and Memcached.ClientLibrary.dll libraries into the "bin" directory of your web site or web application.
  2. Create an instance of the Memcached CFC, initializing it with an array of memcached server addresses and other optional parameters.
  3. Use the Memcached CFC methods to get and set named variables.
Initializing the Memcached CFC requires only that you specify an array of memcached server addresses; there are other optional initialization parameters that are documented within the Memcached.cfc source file. Here's an example of creating and initializing a Memcached CFC instance and saving it within the CFML Application scope for future reference (this code would be placed within the onApplicationStart method of Application.cfc):
<cfset servers = ArrayNew(1)>
<cfset ArrayAppend( servers, "192.168.200.117:11211" )>
<cfset application.memcached = createObject( "component", "Memcached" ).init( servers )>

Now simply use the Set, Get, and other Memcached CFC methods to store and retrieve variables from the memcached servers. For example, here's how you might implement caching of a query variable with a two-hour expiration:

<cfset employees = application.memcached.Get( "employees" )>
<cfif employees eq null>
    <cfquery datasource="ows" name="employees">
    SELECT * FROM Employees
    </cfquery>
    <cfset application.memcached.Set( "employees", employees, DateAdd( "h", 2, Now() ) )>
</cfif>

Some additional information for CFML programmers who are not using BlueDragon.NET:

  • There are two memcached client CFCs that have been written for ColdFusion: cfmemcached and Memcached Client. I don't know if these work on the Java editions of BlueDragon, but I'm sure we could get them to work if you're interested (let me know).

  • Support for memcached has been integrated into OpenBD 1.0, which was just recently released. If this turns out to be a popular feature we'll roll it out in a future release of the commercial BlueDragon editions.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.9.2.001. Contact Blog Owner

company media information terms of use privacy policy contact us
This page was dynamically built on the BlueDragon CFML Engine