You Are Here: Home » How-To » Windows

How to run Memcached in Windows Azure?

By Debjit on March 7th, 2011 
Advertisement

Memcached is a distributed caching system that helps take the load off the database and is used by some of the very big websites. In this article we will tell you how to install Memcached in Windows Azure. After installing and setting up Memcached you will be able to cache any data that is retrieved, thereby reducing the pressure on the database.

You might also be interested in finding out how to install PHP frameworks such as Drupal, Joomla, WordPress & phpBB on Windows Azure Cloud.

Download The Windows Azure Memcached Solution Accelerator from here. There are two versions available - 32bit and the 64bit - download the one you need.

You will also need a Windows Version of Memcached which can be downloaded from here (Link 1) or here (Link 2). The Memcached version of Link 1 above may cause some problems while running, in such case you can use the one at Link 2.

The Memcached module for Windows Azure has a known issue that sometimes the memcached workerrole shows 'Busy' in Windows Azure but if you browse the web role UI, you will see Memcached working fine and you will be able to set and read the values. Also Memcached may take a long time to start for the first time.

Here are a few code samples for The Server Side and Client Side Setup of Memcached in Windows Azure.

Memcached Server on Windows Azure

We have to setup an internal endpoint on the server side that will be used to connect clients to Memcached server. After the node is created we can launch the Memcached server by passing in the cache size and endpoint address as arguments.

string arguments =   "-m " + cacheSize +
" -l " + endpoint.Address +
" -p " + endpoint.Port;ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "memcached.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = arguments; 

After the server setup, we have to setup the client which can be done using the instructions at this page. After which you can use the caching library to set and get values from the cache using the following code:

AzureMemcached.Client.Store(StoreMode.Set, key, value);
AzureMemcached.Client.Get(key);

Advertisement







How to run Memcached in Windows Azure? was originally published on Digitizor.com on February 5, 2010 - 12:35 pm (Indian Standard Time)