While doing some web development, I needed to have Memcached (source code) installed on my local machine to closely simulate what was going on my server. I develop under windows, and realized that installing meme Memcached isn’t as straightforward as it is on Linux. There are actually quite a few people who ask about how to do it, so I’ll give you a couple of good options. Here’s how to install the caching system on Windows.

Solution 1 : install Memcached for Windows (v1.4.5)

cmd-memcached-startThis is the most obvious way to do it. It took me a tiny bit of time to locate the proper files, so I have included the links I used:

  • Download a stable version, in either 32-bit or 64-bit I have tested the 64-bit version.
  • Create a directory such as c:\memcached\ (or something else)
  • Copy the .zip content to that directory. There should be one memcached.exe file by itself (32-bit) or with a couple of .dll files (64-bit)
  • Open a command prompt (need to be opened as administrator). You can do this by going to Start>Search and type “cmd”
  • Type the command “c:\memcached\memcached.exe -d start” to start the service
  • Type the command “c:\memcached\memcached.exe -d stop” to stop the service
  • To change the memory pool size, type “c:\memcached\memcached.exe -m 512” for 512MB

Your Memcached service should now run and wait incoming key/value pairs.

IMPORTANT NOTES:

1– If you want to use this in a local web app, you have to make sure that your language has built-in support for Memcached. For example, PHP may require the installation of additional libraries and modifications of the php.ini configuration file. If there’s a demand for it, I’ll write an explanation for that too.

2– The default configuration is to create a 64MB memory pool and listening on port 11211

3– Type the command “c:\memcached\memcached.exe -d install” to have Memcached started after a reboot. You should now see Memcached as a Windows Service in the control panel. IMPORTANT: if you choose to install it as a service, you lose the ability to change the pool size via command line. You will need to edit a registry key as follows:

  • Launch regedit via Start>Search
  • Find “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached”
  • Edit the “–m VALUE” to the number of desired megabytes “–m 512” = 512 MB

Solution 2: Install Couchbase to replace Memcached

01-couchbase-installerYou may not have heard of it, but Couchbase is a JSON-based document store, but it also has an in-memory key/value store interface that is compatible with Memcached. This means that you can install Couchbase for Windows and configure it to act just like Memcached. The cool thing is that it comes with a cool graphical interface and a regular Windows installer.

Couchbase also has a great failover mechanism and cluster management that Memcached lacks, but this is a bit beyond the scope of this article.

  1. Go to the Couchbase download page
  2. Pick the Windows installer
  3. Launch the installer file

02-couchbase-installer-infoAt the end of the installation process, the browser will open at the address http://localhost:8091/index.html and you will go through the initial setup. The important screen is this one:

04-couchbase-server-configFor Memcached purposes, you can ignore the Disk storage settings, since you will create a memory pool. Just leave things the way they are.

Choose “start a new cluster” and pick the amount of RAM you want to use. Anything between 64 and 512MB will do. It’s really up to you, and you can change this later. Click Next and ignore the Sample buckets. Click Next again.

05-couchbase-memcached-bucket-configThis is another important screen. It’s where you will create the memory pool. Make sure that you pick the Memcached Bucket Type. To emulate Memcached, you probably don’t need to enable the Replicas. But you should enable the Flush command. Click Next.

You can discard the Notifications and the registration if you want. Click Next.

The final phase is to setup your password. Click Next. And voila! You now have a running Memcached node that you can keep an eye on with a cool graphical interface in which you can inspect the content of the cache (useful for debugging!)

06-couchbase-memcached-bucket-overviewThe default port for Memcached buckets is the standard 11211. You can change this in Data Buckets > [Bucket Name] > Edit

Conclusion

You now have two reliable ways to install Memcached on Windows machines. For development purposes, I like Couchbase, but if you want something light, the original Memcache port for Windows can’t be beat. If you have additional questions, just drop a comment, and I’ll do my best to reply. Thanks for reading this.

Filed in Web. Read more about .