cfmemcached v1.2 released today - download yours now

I tested and uploaded a new release for cfmemcached today. This update includes a new java library from each branch. Greg and Dustin updated their code, so i'm passing it along to you for your caching pleasure.

This new release includes a number of upgrades to the coldfusion piece as well.

cfmemcachedNew -

  • included the updated java library from dustin that has some performance fixes
  • Update coldfusion library to have a configurable timeout. Base timeout can be set as well as a time out per request, in case you want to extend it to wait for a long running cache or a bulk operation that needs to wait on several memcached responses
  • more cftries and catches - trying to make the application fail gracefully

cfmemcachedOld -

  • included the updated java library from greg that has some performance fixes
  • added a lot more cftries and catches to make it fail better, ie fail gracefully so that it doesn't impact your overall application.

as always, cfmemcached is located at -- Coldfusion memcached

cfmemcached v1.1 released today

I released a new version of cfmemcached today. I recently went through and made some changes that would make it easier to deploy in different situations. I also made some changes to the new memcached client to make it easier to use and to avoid some timeout issues.


external caching for coldfusion with memcached

What is memcached?

memcached is a lightweight cacheing program that allows you to store objects and items in an easily accessed format. The memcached server stores items in a binary format so that it's easy to get these items back. The memcached server is a very light-weight high-availabilty cache system. For you coldfusion heads out there, you can think of memcached as sort of a large struct in ram that holds your stores whatever you throw at it (with some exceptions). Access is quick and non-locking (so there's no waiting around to get stuff if you have several clients hitting it at one time). The server is a stand alone server that you can get to with a client library which zips info up and sends it to the server for you. Not only that, but the memcached server can be put up wherever you have spare ram that's sitting around unused. You can have several memcached servers sitting around and based on a specific algorithm, the memcached client will go out and fetch your stored items from it's servers, however many there are.

Wait... caching? coldfusion already has that... why bother?

True, coldfusion already has caching. it'll cache queries and it'll cache whatever you want in the application and server scopes. in fact you might not get much out of memcached unless you are trying to run a high-page hit site or are trying to cache a ton of data. For example, coldfusion runs on java under a java instance. there are limitations to the amount of memory you can safely use in coldfusion without running into problems.

These are underlying java limitations for the most part, because java intances can only have up to 2 gigs (if you are running cf 7) and i think 4 gigs if you are running cf 8 and remember, coldfusion takes up some of that ram for itself (about 100 mb). I had the opportunity of working at a company where their instance of coldfusion was having a hard time staying up because it was stuffed with too much cached information. The more info you have, the more coldfusion has to keep track of it, and the more your garbage collection has to run on that java instance (to clear out new space) and garbage collection running over 500 mb is faster than running across 2-4 gigs.

What memcached allows you to do is to offload that garbage collecting to a separate process and possibly into other servers if needed. It also allows you to off-load memory allocation costs to other machines. For example, if you have a large coldfusion machine with 10 gigs of ram and you are only running 1 instance of coldfusion, that's potentially 4-8 more gigs of ram that is sitting around unused.

Another nice thing about memcached is that if you have to restart coldfusion, you don't have to reload all those cached items. As long as the memcached server stays up, you can access those items.

Sure memcached sounds good, but aren't there some drawbacks?

Yup, there are some drawbacks to using memcached, like 1. using memcached takes a little more code to use than to store stuff in coldfusion. In coldfusion you can do this:

<cfquery name="mytestquery" datasource="mydatasource" cachedwithin="#createtimespan(1,0,0,0)#">
      .... query here

and you're done.. however, to use memcached, it takes a bit more code:

if ( variables.memcached.keyExists("mykey")   {
      mytestquery = variables.memcached.get("mykey");
   } else    {
      <cfquery name="mytestquery" datasource="mydatasource">
      .... query here

All in all, it's a little more code, but not a ton. It does get more involved if you are storing the query based off of parameters. Coldfusion automagically saves and updates stored queries based on the query parameters, whereas you have to manage that in memcached. It's not tragic, but its a bit more work. However, one benefit that you gain is that you can access the stored queries and purge the cached items whenever you want. You are able to do that in coldfusion as well, but you have more control over it with memcached.

That all sounds nice, where can i find it?

You can find the coldfusion memcached client here:

You can get the memcached server here:

BlogCFC was created by Raymond Camden. This blog is running version 5.7.