Login Try it Free

Memcached

Last Updated: Jun 13, 2012 12:00PM MDT

Memcached is a distributed memory caching system that caches data and objects in RAM and can be a great tool for optimizing your app. After reading this guide, you will be familiar with:

  •  Adding a Memcached component to your app
  •  Connecting your app to your Memcached component

Memcached and Red Frowny Faces

Memcached components are by nature different from web and database components. Instead of using RAM to access information, Memcached uses RAM to store information. This means the more Memcached does what it's supposed to do (store cached files), the more RAM it will use. Eventually, it will use all the RAM allocated to it and start to drop the oldest cached files (just like it's designed to do).

So what does this mean? It means that a red frowny face on your Memcached component is totally normal. Scaling will allow you to store more information, but a Memcached component will always end up using 100% of its RAM.

Add the Memcache PHP Extension to Your Boxfile

To use your Memcached component, you must first add the "memcache" php extension to your web component. This is done in your Boxfile.

 YAMLEnabling the Memcache Extension in Your Boxfile 

/Boxfile

Creating a Memcached Component

Through the App Dashboard

Creating a Memcached component through your app dashboard is simple. Start by clicking the "Add Cache" button.

  Add Cache  

Select Memcached as your cache type. Select Cloud or Dedicated (Currently we only off cloud instances, but dedicated instances are coming). Then, if you would like, name your Memcached component. If you don't name it, it will be assigned a random name. Click "Create" and your Memcached component will be created.

From the Boxfile

To create a Memcached instance from your Boxfile, simply include following.

 YAMLCreating a Memcached Instance from Your Boxfile 

/Boxfile

On your next deploy, a Memcached instance will be created.

Connecting to Memcached

Because applications vary widely in how they connect to Memcached, it's hard to give you a generic code example of how to connect to your Memcached instance. What is uniform is the need for a Host and Port to connect to. These can be found in your app dashboard.

To get your Memcached credentials, click on your cache component in your app dashboard to expand your component details. Click on the "Show Credentials" link in the bottom left of your component details.

     

Your Host is "tunnel.pagodabox.com" and your port is the number provided at the end. Once these credentials are in the correct location in your source code, you should be good to go.

Tunneling into Memcached

Memcached components are tunnelable, much like database components. So you can tunnel into them using the Pagoda Gem.

 TerminalTunnel Connection 

Open another terminal window and telnet into the Memcached component using the host and port number you were given by the tunnel command.

 TerminalTelnet into Component 

Once telnet has connected, you can run commands like:

 TerminalMemcached Telnet Commands 

If you have any suggestions or corrections for this guide, please submit a ticket.

Contact Us