Fork me on GitHub

Getting Started with MemCachier

MemCachier is an implementation of the Memcache in-memory key/value store used for caching data. Memcache a key technology in modern web applications for scaling and reducing server loads. MemCachier manages and scales clusters of memcache servers so you can focus on your app. Tell us how much memory you need and get started for free instantly. Add capacity later as you need it.

Below is our user guide for using MemCachier, you can also find answers in our FAQ.

Table of Contents

  1. Ruby
  2. Rails 3 & 4
  3. Rails 2
  4. Ruby Puma Webserver
  5. Rack::Cache
  6. Python
  7. Django
  8. PHP
  9. WordPress
  10. CakePHP
  11. Symfony2
  12. Laravel
  13. Node.js
  14. Java
  15. Supported client libraries
  16. Example applications
  17. Local usage
  18. MemCachier analytics
  19. Advanced analytics
  20. New Relic integration
  21. Changing plans
  22. Usage Documentation
  23. Key-Value size limit
  24. Errors connecting to localhost
  25. Getting support

Ruby

Start by adding the dalli gem to your Gemfile.

gem 'dalli'

Then bundle install:

$ bundle install

Dalli is a Ruby memcache client. Once it is installed you can start writing code. The following is a basic example showing get and set.

cache = Dalli::Client.new(<MEMCACHIER_SERVERS>.split(","),
                    {:username => <MEMCACHIER_USERNAME>,
                     :password => <MEMCACHIER_PASSWORD>
                     :failover => true,
                     :socket_timeout => 1.5,
                     :socket_failure_delay => 0.2
                    })

The values for <MEMCACHIER_SERVERS>, <MEMCACHIER_USERNAME>, and <MEMCACHIER_PASSWORD> are listed on your cache overview page.

From here you can use the following code examples to use the cache in your Ruby app:

cache.set("foo", "bar")
puts cache.get("foo")

You can also get an insight into your cache usage (number of keys stored and bytes) with the stats command:

cache.stats
=> {"memcachier.example.net:11211" => {"cur_items" => "49982", "bytes" => "89982234"} }

We’ve built a small Ruby example using Sinatra here: MemCachier Sinatra Sample App.

Rails 3 & 4

Start by adding the dalli gem to your Gemfile.

gem 'dalli'

Then bundle install:

$ bundle install

Dalli is a Ruby memcache client. Once it is installed you’ll want to configure the Rails cache_store appropriately. Modify config/environments/production.rb with the following:

config.cache_store = :dalli_store, <MEMCACHIER_SERVERS>.split(","),
                    {:username => <MEMCACHIER_USERNAME>,
                     :password => <MEMCACHIER_PASSWORD>
                     :failover => true,
                     :socket_timeout => 1.5,
                     :socket_failure_delay => 0.2
                    }

The values for <MEMCACHIER_SERVERS>, <MEMCACHIER_USERNAME>, and <MEMCACHIER_PASSWORD> are listed on your cache overview page.

In your development environment, Rails.cache defaults to a simple in-memory store and so it doesn’t require a running memcached.

From here you can use the following code examples to use the cache in your Rails app:

Rails.cache.write("foo", "bar")
puts Rails.cache.read("foo")

We’ve built a small Rails example here: MemCachier Rails sample app.

Rails 2

Start by adding the dalli gem to your Gemfile. You will need to use dalli v1.0.5 as later versions of Dalli don't support Rails 2.

gem 'memcachier'
gem 'dalli', '~>1.0.5'

Then bundle install:

$ bundle install

Dalli is a Ruby memcache client. Once it is installed you’ll want to configure the Rails cache_store appropriately. Modify config/environments/production.rb with the following:

require 'active_support/cache/dalli_store23'
config.cache_store = :dalli_store, <MEMCACHIER_SERVERS>.split(","),
                    {:username => <MEMCACHIER_USERNAME>,
                     :password => <MEMCACHIER_PASSWORD>
                     :failover => true,
                     :socket_timeout => 1.5,
                     :socket_failure_delay => 0.2
                    }

The values for <MEMCACHIER_SERVERS>, <MEMCACHIER_USERNAME>, and <MEMCACHIER_PASSWORD> are listed on your cache overview page.

In your development environment, Rails.cache defaults to a simple in-memory store and so it doesn’t require a running memcached.

Also modifyconfig/environment.rb to contain:

config.gem 'dalli'

From here you can use the following code examples to use the cache in your Rails app:

Rails.cache.write("foo", "bar")
puts Rails.cache.read("foo")

We’ve built a small Rails (3 & 4) example here: MemCachier Rails sample app.

Ruby Puma Webserver

If you are using the Puma webserver for your Ruby app (Rails or otherwise), then you should take some additional steps due to the multi-threaded runtime being used. This applies to all threaded webservers for Ruby, not just Puma.

First, please refer to the documentation on Rails or Ruby above appropriately, and then take these additional steps.

Dalli by default uses a single connection to each server. This works fine normally, but can be come a bottleneck in a multi-threaded environment and limit performance. In this case, Dalli support connection pooling, where multiple connections are created to MemCachier's servers. To use this, start by adding the connection_pool gem to your Gemfile:

gem 'connection_pool'

Next, you'll need to set the :pool_size configuration option when setting up Dalli. For example, in Rails 3 & 4 your configuration would become:

config.cache_store = :dalli_store,
                    (ENV["MEMCACHIER_SERVERS"] || "").split(","),
                    {:username => ENV["MEMCACHIER_USERNAME"],
                     :password => ENV["MEMCACHIER_PASSWORD"],
                     :failover => true,
                     :socket_timeout => 1.5,
                     :socket_failure_delay => 0.2,
                     :pool_size => 5
                    }

Where the number 5 should be chosen according to how many threads you will be running and the available concurrency on the machines running your webserver.

Rails Rack::Cache

Rails can use a middle-ware component of the Rack web server architecture called Rack::Cache. This provides caching of static assets in Rails and is a simple alternative to use a full CDN.

Please see this article for information.

Python

We support the `pylibmc` memcache client as it has great performance and recently added Python 3 support. However, it can sometimes be difficult to install locally as it relies on the C libmemcached library. If you prefer, you can try a pure python client, [python-binary-memcached](https://github.com/jaysonsantos/python-binary-memcached), which works well but only supports Python 2 right now.

Here we explain how you setup and install MemCachier with Python.

MemCachier has been tested with the pylibmc memcache client. This client relies on the C libmemcached library. This should be fairly straight-forward to install with your package manager on Linux or Windows. We also have a blog post for Ubuntu users on how to do this. Once it's installed, then install pylibmc:

$ pip install pylibmc

Be sure to update your requirements.txt file with these new requirements (note that your versions may differ than what’s below):

pylibmc==1.5.0

Heroku Users: The above `pylibmc` requirements must be added directly to your `requirements.txt` file. They shouldn't be placed in an included pip requirement file. The Heroku Python buildpack checks the `requirements.txt` file and only that file for the presence of `pylibmc` to trigger bootstrapping `libmemcached`, which is prerequisite for installing `pylibmc`.

Next, configure your settings.py file the following way:

import pylibmc

servers = os.environ.get('MEMCACHIER_SERVERS', '').split(',')
user = os.environ.get('MEMCACHIER_USERNAME', '')
pass = os.environ.get('MEMCACHIER_PASSWORD', '')

mc = pylibmc.Client(servers, binary=True,
                    username=user, password=pass,
                    behaviors={
                      # Faster IO
                      "tcp_nodelay": True,
                      "no_block": True,

                      # Timeout for set/get requests
                      "_poll_timeout": 2000,

                      # Use consistent hashing for failover
                      "ketama": True,

                      # Configure failover timings
                      "connect_timeout": 2000,
                      "remove_failed": 4,
                      "retry_timeout": 2,
                      "dead_timeout": 10,
                    })

After this, you can start writing cache code in your Python app:

mc.set("foo", "bar")
print mc.get("foo")

A confusing error message you may get from `pylibmc` is MemcachedError: error 37 from memcached_set: SYSTEM ERROR (Resource temporarily unavailable). This indicates that you are trying to store a value larger than 1MB. MemCachier has a hard limit of 1MB for the size of key-value pairs. To work around this, either consider sharding the data or using a different technology. The benefit of an in-memory key-value store diminishes at 1MB and higher.

Django

MemCachier has been tested with the pylibmc memcache client, but the default django pylibmc client doesn’t support SASL authentication. Recently pylibmc added Python 3 support in version 1.4.0.

This client relies on the C libmemcached library. This should be fairly straight-forward to install with your package manager on Linux or Windows. We also have a blog post for Ubuntu users on how to do this.

Once it's installed, then install pylibmc:

$ pip install pylibmc django-pylibmc

Be sure to update your requirements.txt file with these new requirements (note that your versions may differ than what’s below):

pylibmc==1.5.0
django-pylibmc==0.6.0

Heroku Users: The above `pylibmc` requirements must be added directly to your `requirements.txt` file. They shouldn't be placed in an included pip requirement file. The Heroku Python buildpack checks the `requirements.txt` file and only that file for the presence of `pylibmc` to trigger bootstrapping `libmemcached`, which is prerequisite for installing `pylibmc`.

Next, configure your settings.py file the following way:

os.environ['MEMCACHE_SERVERS'] = os.environ.get('MEMCACHIER_SERVERS', '').replace(',', ';')
os.environ['MEMCACHE_USERNAME'] = os.environ.get('MEMCACHIER_USERNAME', '')
os.environ['MEMCACHE_PASSWORD'] = os.environ.get('MEMCACHIER_PASSWORD', '')

CACHES = {
    'default': {
        # Use pylibmc
        'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',

        # Use binary memcache protocol (needed for authentication)
        'BINARY': True,

        # TIMEOUT is not the connection timeout! It's the default expiration
        # timeout that should be applied to keys! Setting it to `None`
        # disables expiration.
        'TIMEOUT': None,

        'OPTIONS': {
            # Enable faster IO
            'no_block': True,
            'tcp_nodelay': True,

            # Keep connection alive
            'tcp_keepalive': True,

            # Timeout for set/get requests
            '_poll_timeout': 2000,

            # Use consistent hashing for failover
            'ketama': True,

            # Configure failover timings
            'connect_timeout': 2000,
            'remove_failed': 4,
            'retry_timeout': 2,
            'dead_timeout': 10
        }
    }
}

The values for <MEMCACHIER_SERVERS>, <MEMCACHIER_USERNAME>, and <MEMCACHIER_PASSWORD> are listed on your cache overview page. Note that Django expects to be semicolon-delimited (while we provide it comma-eliminated).

Finally, we also strongly recommend that you place the following code in your wsgi.py file to correct a serious performance bug (#11331) with Django and memcached. The fix enables persistent connections under Django, which by default uses a new connection for each request:

# Fix django closing connection to MemCachier after every request (#11331)
from django.core.cache.backends.memcached import BaseMemcachedCache
BaseMemcachedCache.close = lambda self, **kwargs: None

After this, you can start writing cache code in your Django app:

from django.core.cache import cache
cache.set("foo", "bar")
print cache.get("foo")

We’ve built a small Django example here: MemCachier Django sample app.

You may also be interested in the django-heroku-memcacheify pip, which fully configures MemCachier with one line of code for any Django app the pip supports.

A confusing error message you may get from `pylibmc` is MemcachedError: error 37 from memcached_set: SYSTEM ERROR (Resource temporarily unavailable). This indicates that you are trying to store a value larger than 1MB. MemCachier has a hard limit of 1MB for the size of key-value pairs. To work around this, either consider sharding the data or using a different technology. The benefit of an in-memory key-value store diminishes at 1MB and higher.

PHP

We recommended you use the PHP Memcached client to connect with MemCachier. It supports the full protocol and has great performance. We also recommend that you use the composer dependency manager for PHP, although that is up to you.

It can be difficult to get the memcached client to work as it requires that you build it against a version of libmemcached (a C library that the PHP client relies upon) that support SASL authentication, which often isn't enabled by default. If you have trouble, please open a support ticket with us. Alternatively, you could use a pure PHP client that MemCachier supports, instructions on how are here.

First, if using composer, you'll need to modify your composer.json file to include the module:

{
    "require": {
        "php": ">=5.3.2",
        "ext-memcached": "*"
    }
}

Then, you can connect to MemCachier using the client:

require 'vendor/autoload.php';

// create a new persistent client
$m = new Memcached("memcached_pool");
$m->setOption(Memcached::OPT_BINARY_PROTOCOL, TRUE);

// some nicer default options
$m->setOption(Memcached::OPT_NO_BLOCK, TRUE);
$m->setOption(Memcached::OPT_AUTO_EJECT_HOSTS, TRUE);
$m->setOption(Memcached::OPT_CONNECT_TIMEOUT, 2000);
$m->setOption(Memcached::OPT_POLL_TIMEOUT, 2000);
$m->setOption(Memcached::OPT_RETRY_TIMEOUT, 2);

// setup authentication
$m->setSaslAuthData( <MEMCACHIER_USERNAME>
                   , <MEMCACHIER_PASSWORD> );

// We use a consistent connection to memcached, so only add in the
// servers first time through otherwise we end up duplicating our
// connections to the server.
if (!$m->getServerList()) {
    // parse server config
    $servers = explode(",", <MEMCACHIER_SERVERS>);
    foreach ($servers as $s) {
        $parts = explode(":", $s);
        $m->addServers($parts[0], $parts[1]);
    }
}

The values for <MEMCACHIER_SERVERS>, <MEMCACHIER_USERNAME>, and <MEMCACHIER_PASSWORD> are listed on your cache overview page.

You should look at the PHP Memcached client documentation for a list of API calls you can make against MemCachier.

We’ve built a small PHP example here: MemCachier PHP sample app.

PHP Session Support

You can configure PHP to store sessions in MemCachier as follows.

First, start by configuring an appropriate .user.ini in your document root. It should contain the following:

session.save_handler=memcached
memcached.sess_binary=1
session.save_path="PERSISTENT=myapp_session <MEMCACHIER_SERVERS>"
memcached.sess_sasl_username=<MEMCACHIER_USERNAME>
memcached.sess_sasl_password=<MEMCACHIER_PASSWORD>

In your code you should then be able to run:

// Enable MemCachier session support
session_start();
$_SESSION['test'] = 42;

PHP -- MemcacheSASL

This is not our recommended client for using MemCachier from PHP. We recommend the php memcached client. However, it is an easier client to use as it's a pure PHP implementation while the recommended php client requires a C extension to be installed with SASL support. It doesn't support multiple proxy servers like the memcached client but is otherwise quite good.

You should first install the PHPMemcacheSASL client. You can either grab the code directly or use composer for package management. We suggest composer.

First, if using composer, you'll need to modify your composer.json file to include the module:

{
    "require": {
        "php": ">=5.3.2",
        "memcachier/php-memcache-sasl": ">=1.0.1"
    }
}

Then, you can connect to MemCachier using the client:

require 'vendor/autoload.php';
use MemCachier\MemcacheSASL;

// Create client
$m = new MemcacheSASL();
$servers = explode(",", <MEMCACHIER_SERVERS>);
foreach ($servers as $s) {
    $parts = explode(":", $s);
    $m->addServer($parts[0], $parts[1]);
}

// Setup authentication
$m->setSaslAuthData( getenv("MEMCACHIER_USERNAME")
                   , getenv("MEMCACHIER_PASSWORD") );

$m->add("foo", "bar");
echo $m->get("foo");

The values for <MEMCACHIER_SERVERS>, <MEMCACHIER_USERNAME>, and <MEMCACHIER_PASSWORD> are listed on your cache overview page.

We’ve built a small PHP example here: MemCachier PHP sample app.

WordPress

We support WordPress through two different options. The first you can find here, and uses the binary memcache protocol and is supported by us. It should be easy to install, simply follow the instructions on the Git repo.

We also have a community support alternative approach that uses the ASCII memcache protocol, which is far easier to get running on your own servers if you aren't using a hosted platform like Heroku. You can find it on GitHub here. Please follow the instructions on the repo page.

CakePHP

The CakePHP framework has excellent support for caching and can be easily used with MemCachier as the provider. To setup CakePHP with MemCachier, you'll need to edit the file app/Config/bootstrap.php and add the following lines:

Cache::config('default', array(
    'engine' => 'Memcached',
    'prefix' => 'mc_',
    'duration' => '+7 days',
    'servers' => explode(',', <MEMCACHIER_SERVERS>),
    'compress' => false,
    'persistent' => 'memcachier',
    'login' => <MEMCACHIER_USERNAME>,
    'password' => <MEMCACHIER_PASSWORD>,
    'serialize' => 'php'
));

After that, you should be able to use caching throughout your application like so:

class Post extends AppModel {

    public function newest() {
        $model = $this;
        return Cache::remember('newest_posts', function() use ($model){
            return $model->find('all', array(
                'order' => 'Post.updated DESC',
                'limit' => 10
            ));
        }, 'longterm');
    }
}

The above will fetch the value associated with the key newest_posts from the cache if it exists. Otherwise, it will execute the function and SQL query, storing the result in the cache using the newest_posts key.

You can find much more information on how to use caching with CakePHP here.

Symfony2

The Symfony2 framework is a great choice with MemCachier. It supports caching and storing sessions in MemCachier.

First, start by configuring an appropriate .user.ini in your document root. It should contain the following:

session.save_handler=memcached
memcached.sess_binary=1
session.save_path="PERSISTENT=myapp_session <MEMCACHIER_SERVERS>"
memcached.sess_sasl_username=<MEMCACHIER_USERNAME>
memcached.sess_sasl_password=<MEMCACHIER_PASSWORD>

Laravel

We have community provided support for the Laravel PHP webframework. You can find a caching backend with MemCachier support on Github here. Please follow the instructions on the repo page.

Node.js

For Node.js we recommend the use of the memjs client library. It is written and supported by MemCachier itself! To install, use the node package manager (npm):

npm install memjs

Using it is straight-forward as memjs understands the MEMCACHIER_SERVERS, MEMCACHIER_USERNAME and MEMCACHIER_PASSWORD environment variables that the MemCachier add-on setups. For example:

var memjs = require('memjs')
var mc = memjs.Client.create()
client.get('hello', function(val) {
    alert(val)
})

We’ve built a small Node.js example here: MemCachier Node.js sample app.

Java

For Java we recommend using the SpyMemcached client. We also recommend using the Apache Maven build manager for working with Java applications. If you aren't using maven and are instead using Apache Ant or your own build system, then simply add the spymemcached jar file as a dependency of your application.

Please make sure to use version 2.8.9 or earlier! At the moment, version 2.8.10 and later have an issue with SASL authentication that makes them unusable with MemCachier.

For maven however, start by configuring it to have the proper spymemcached repository:

<repository>
  <id>spy</id>
  <name>Spy Repository</name>
  <layout>default</layout>
  <url>http://files.couchbase.com/maven2/</url>
  <snapshots>
    <enabled>false</enabled>
  </snapshots>
</repository>

Then add the spymemcached library to your dependencies:

<dependency>
  <groupId>spy</groupId>
  <artifactId>spymemcached</artifactId>
  <version>2.8.1</version>
  <scope>provided</scope>
</dependency>

Once your build system is configured, you can start adding caching to your Java app:

import java.io.IOException;
import net.spy.memcached.AddrUtil;
import net.spy.memcached.MemcachedClient;
import net.spy.memcached.ConnectionFactoryBuilder;
import net.spy.memcached.auth.PlainCallbackHandler;
import net.spy.memcached.auth.AuthDescriptor;

public class Foo {
  public static void main(String[] args) {
    AuthDescriptor ad = new AuthDescriptor(new String[] { "PLAIN" },
        new PlainCallbackHandler(<MEMCACHIER_USERNAME>,
            <MEMCACHIER_PASSWORD>));

    try {
      MemcachedClient mc = new MemcachedClient(new ConnectionFactoryBuilder()
          .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY)
          .setAuthDescriptor(ad).build(), AddrUtil.getAddresses(<MEMCACHIER_SERVERS>));
      mc.set("foo", "bar");
      System.out.println(mc.get("foo"));
    } catch (IOException ioe) {
      System.err.println("Couldn't create a connection to MemCachier: \nIOException "
              + ioe.getMessage());
    }
  }
}

The values for <MEMCACHIER_SERVERS>, <MEMCACHIER_USERNAME>, and <MEMCACHIER_PASSWORD> are listed on your cache overview page.

You may wish to look the spymemcached JavaDocs or some more example code to help in using MemCachier effectively.

We’ve built a small Java example here, using Jetty: MemCachier Java Jetty sample app.

Client library support

MemCachier will work with any memcached binding that supports SASL authentication and the binary protocol. We have tested MemCachier with the following language bindings, although the chances are good that other SASL binary protocol packages will also work.

Language Bindings
Ruby dalli
Python pylibmc
Django django-pylibmc
PHP PHPMemcacheSASL or PHP Memcached
Node.js memjs
Java spymemcached (version 2.8.9 or earlier) or xmemcached
Go mc
Haskell memcache

Sample applications

We've built a number of working sample apps, too. Though keep in mind that these apps are built for Heroku, so they expect MEMCACHIER_SERVERS, MEMCACHIER_USERNAME, and MEMCACHIER_PASSWORD to be in the environment.

Local usage

To test against your application locally, you will need to run a local memcached process. MemCachier is only available from the datacenter you signed up for. But because MemCachier and memcached speak the same protocol, you shouldn’t have any issues testing locally. Installation depends on your platform.

The below examples will install memcached without SASL authentication support. This is generally what you want as client code can still try to use SASL auth and memcached will simply ignore the requests which is the same as allowing any credentials. So your client code can run without modification locally.

On Ubuntu:

$ sudo apt-get install memcached

Or on OS X (with Homebrew):

$ brew install memcached

Or for Windows please refer to these instructions

For further information and resources (such as the memcached source code) please refer to the Memcache.org homepage

To run memcached simply execute the following command:

$ memcached -v

MemCachier analytics

Our analytics dashboard is a simple tool that gives you more insight into how you’re using memcache. Here's a screenshot of the dashboard:

Analytics dashboard

To access your application's analytics dashboard login to your account and view one of your caches.

The analytics displayed are:

  • Limit -- Your current cache size and memory limit. Once usage comes close to this amount you will start seeing evictions.
  • Live Connections -- Number of connections currently open to your cache.
  • Total connections -- Number of connections ever made to your cache. (So always larger than live connections).
  • Items -- Number of items currently stored in your cache.
  • Evictions -- Number of items ever evicted from your cache due to memory pressure. Items are evicted in an LRU order.
  • New Evictions -- Number of evictions that have occured since the last time we sampled your cache.
  • Hit Rate -- The ratio of get commands that return an item (hit) vs. the number that return nothing (miss). This ratio is for the period between now and when we last sampled your cache.
  • Set Cmds -- Number of times you have ever performed a set command.
  • Flush Cmds -- Number of times you have ever performned a flush command.

With the basic analytics dashboard we sample your cache once per hour. With the advance dashboard we sample it once every 30 minutes.

Advanced analytics

We offer higher paying customers an advance version of our analytics dashboard. Currently, this offers two primary advantages:

  • Higher Sample Rate -- We sample the cache for collecting analytics once every thirty minutes, twice the rate of the basic analytics dashboard. We don't sample more often than that as a higher granularity hasn't proven to be useful, it leads to more noise and less signal.
  • More Graphs -- We offer two additional graphs for the advanced analytics dashboard.
    • Eviction Graph -- Your new evictions tracked over time.
    • Connection Graph -- Your new connecions tracked over time.

New Relic integration

MemCachier supports integration with your New Relic dashboard if you happen to be a customer of both MemCachier and New Relic. Currently this feature is only available to caches of 500MB or larger. A blog post showing the integration can be found here.

To setup the integration you will need to find your New Relic license key. This can be done by going to your "Account Settings" page when logged in to New Relic by click on your New Relic username in the top right corner. Then you will find your license key in the right side information column. It should be exactly 40 characters long. Please refer to the blog post for a visual walkthrough.

Once you have your New Relic licence key, it can be entered for your cache on the analytics dashboard page. In the bottom right corner there is a button to do this.

Upgrading and downgrading

Changing your plan, either by upgrading or downgrading, requires no code changes. Your cache won't be lost, either. Upgrading and downgrading Just Works™. Also, you are only ever charged by the hour for the time that you are on a certain plan. So try experimenting with different cache sizes knowing that you will only be charged for the hours you are on a plan, not for a whole month.

Changing your plan, either by upgrading or downgrading, can be done easily at any time through your account.

  • No code changes are required.
  • Your cache won't be lost or reset*.
  • You are charged by the hour for plans, so try experimenting with different cache sizes with low cost.

* When moving between the development plan to a production plan, you will loose your cache. This is unavoidable due to the strong separation between the development and production clusters.

Using MemCachier

Please refer to your client or framework documentation for how to use MemCachier effectively.

MemCachier Guides:

Framework and Client Documentation:

Key-Value size limit (1MB)

MemCachier has a maximum size that a key-value object can be of 1MB. This applies to both key-value pairs created through a set command, or existing key-value pairs grown through the use of an append or prepend command. In the later case, the size of the key-value pair with the new data added to it, must still be less than 1MB.

The 1MB limit applies to the size of the key and the value together. A key of size 512KB with a value of 712KB would be in violation of the 1MB limit.

The reason for this has partially to do with how memory is managed in MemCachier. A limitation of the high performance design is a restriction on how large key-value pairs can become. Another reason is that storing values larger than 1MB doesn't normally make sense in a high-performance key-value store. The network transfer time in these situations becomes the limiting factor for performance. A disk cache or even a database makes sense for this size value.

Errors about app trying to connect to localhost

By default, most memcache client look for the environment variables, MEMCACHE_SERVERS, MEMCACHE_USERNAME and MEMCACHE_PASSWORD for their configuration. These variables are used when the initialization code for the memcache client doesn't specifically specify these values.

If these environment variables aren't set, clients generally default to connecting to 127.0.0.1:11211 (i.e., localhost), with no username and password.

The MemCachier add-on sets the MEMCACHIER_SERVERS, MEMCACHIER_USERNAME and MEMCACHIER_PASSWORD environment variables. So you need to either set the equivalent MEMCACHE_* variables from these, or pass these values to your client when you create a new one in your code.

For example, pseudo-code for the first approach is:

env[MEMCACHE_SERVERS] = env[MEMCACHIER_SERVERS]
env[MEMCACHE_USERNAME] = env[MEMCACHIER_USERNAME]
env[MEMCACHE_PASSWORD] = env[MEMCACHIER_PASSWORD]

While pseudo-code for the second approach is:

memClient = new MemcacheClient(ENV['MEMCACHIER_SERVERS'],
                               ENV['MEMCACHIER_USERNAME'],
                               ENV['MEMCACHIER_PASSWORD'])

Please be careful that you have setup the your client in all locations. Many frameworks, such as Rails, use memcache in multiple ways and may require you to setup initialization properly in a few locations. Generally the first approach is preferred as it is global while the second approach is local to each initialization.

For example, with Ruby on Rails, you'll need to setup cache_store, Rack::Cache and the session_store.

Support

All MemCachier support and runtime issues should be submitted via email to support@memcachier.com or through our support site.

Any issues related to MemCachier service are reported at MemCachier Status.

Please also follow us on twitter, @memcachier, for status and product announcements.