Windows Azure Memcached plugin

Update: Fixed broken link.

Cutting a really long story short. I wanted an easy way of adding caching to a Windows Azure project. Several people I know are already using Memcached, while waiting for our own caching service to go into production. I thought, this should be a plugin.

A plugin is exactly what it sounds, it is something that gets “plugged” into your role at build time. You can see the existing plugins on you have installed by looking at C:\Program Files\Windows Azure SDK\v1.3\bin\plugins. You should see plugins for diagnostics, RemoteAccess and more.

To make your own plugin is fairly easy – if you look in any of the plugin folders you will see a .CSPLUGIN file. You should be able to work out how this works. If you cannot, you probably don’t want to be building your own.

For the Memcached plugin, all I really need is the memcached.exe file (and any dependencies( I used the version from, plus a little wrapper to read the config and launch memcached with the correct parameters – and of course the CSPLUGIN file:

<?xml version="1.0" ?>
    <Task commandLine="Memcached64Plugin.exe" taskType="background" executionContext="limited"/>
    <InternalEndpoint name="Endpoint" protocol="tcp" port="11212" />
    <Setting name="CacheSizeInMB"/>

What the above essentially does is:

  1. Adds a startup task
  2. Adds an InternalEndpoint for port 11212
  3. Adds a CacheSizeInMb setting

The little wrapper was written as a console app:

static void Main()

    var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Memcached64Plugin.Endpoint"].IPEndpoint;
    var cacheSize = RoleEnvironment.GetConfigurationSettingValue("Memcached64Plugin.CacheSizeInMB");
    var startupInfo = new ProcessStartInfo("memcached.exe", string.Format("-m {0} -p {1}", cacheSize, endpoint.Port));


Note when we read the values we use the format <name of the plugin>.<key>, rather than just <key>, in this case Memcached64Plugin.Endpoint, rather than just Endpoint.

Once you build the solution and copy the files into the plugin folder, you can then use the Imports tag in your ServiceConfiguration.csdef file:

 <Import moduleName="Memcached64Plugin" />

This will magically add the correct settings to your ServiceConfiguration.cscfg file as shown:

      <Setting name="Memcached64Plugin.CacheSizeInMB" value="512" />

Note, you won’t see the internal port or the startup task.

When you build and deploy (or even run in the Compute Emulator) the plugin will be packaged up with your code and executed on boot.

For the client side, I used the enyim client, which you can grab from

You can grab a list of memcached servers using the RoleEnvironment, something like:

RoleEnvironment.Roles["WebRole1"].Instances.Select(instance => instance.InstanceEndpoints["Memcached64Plugin.Endpoint"].IPEndpoint)

Note the role is WebRole1 and the port we are looking for is the one we defined in the CSPLUGIN!

You should also write some code to handle a topology change, including adding more instances (or removing instances). You can do this by adding code to handle the RoleEnvironment.Changed event, and rebuilding your server list.

You can grab my plugin below, minus the memcached.exe and required dll. You can download those from the


PS: No, this was nothing to do with PowerShell, I hit an issue with that which I’m still working on – cross your fingers – it will be splendid.

3 thoughts on “Windows Azure Memcached plugin

  1. It was my understanding that there was some native AppFabric caching solution in Azure. Is that just not available yet so you’re using memcached or is there something I’m missing?

    1. Hi James, Yes, there is a native AppFabric Caching solution, which is currently in CTP. Once that ships you can and should go ahead and use that service. Memcached works fine, and is used by many existing websites, so making it work nice on Windows Azure just seemed a good thing to go and do. Nice to have choice right?

Comments are closed.