MemCachier

Page last updated:

MemCachier is an implementation of the Memcache in-memory key-value store used for caching data. MemCachier is a key technology for scaling and reducing server loads in web applications. The MemCachier add-on manages and scales clusters of memcache servers so that operators can focus on their applications.

MemCachier will work with any memcached binding that supports SASL authentication and the binary protocol.

MemCachier also supports integration with your New Relic dashboard if you are a customer of both MemCachier and New Relic and if your cache is 500MB or larger. For more information on this integration, refer to this blog post.

Tell us how much memory you need and get started for free instantly. You can add capacity later as the need arises.

Managing Services

Refer to the Managing Service Instances with the CLI topic for more information.

Creating a MemCachier Service

Create a MemCachier service with the following command:

$ cf create-service memcachier PLAN_NAME INSTANCE_NAME

where PLAN_NAME is the name of the desired plan and INSTANCE_NAME is a name meaningful to you.

Binding Your MemCachier Service

Bind your MemCachier service to your app using the following command:

$ cf bind-service APP_NAME INSTANCE_NAME

Once your MemCachier service is bound to your app, the service credentials will be stored in the VCAP_SERVICES environment variable in the following format:

{
  "memcachier": [
    {
      "name":"Memcachier1",
      "label":"memcachier",
      "tags":[ "Data Stores","Data Store","Caching","key-value","caching" ],
      "plan":"dev",
      "credentials":{
        "servers":"mc5.dev.ec2.memcachier.com:11211",
        "username":"username",
        "password":"password"
      }
    }
  ]
}

For more information, see Delivering Service Credentials to an Application and VCAP_SERVICES Environment Variable.

Using MemCachier with Ruby

Start by adding the Dalli gem to your Gemfile. Dalli is a high performance Ruby memcache client.

gem 'dalli'

Then run bundle install.

Before writing code, you need to create a client object with the correct credentials and settings as the example below shows:

require 'dalli'
credentials = memcachier_servers = memcachier_username = memcachier_password = ''
if !ENV['VCAP_SERVICES'].blank?
  JSON.parse(ENV['VCAP_SERVICES']).each do |k,v|
    if !k.scan("memcachier").blank?
      credentials = v.first.select {|k1,v1| k1 == "credentials"}["credentials"]
      memcachier_servers = credentials["servers"]
      memcachier_username = credentials["username"]
      memcachier_password = credentials["password"]
    end
  end
end
cache = Dalli::Client.new((memcachier_servers || "").split(","),
                    {:username => memcachier_username,
                     :password => memcachier_password,
                     :failover => true,
                     :socket_timeout => 1.5,
                     :socket_failure_delay => 0.2})

You can now use the cache through operations such as get and set, as the example shows:

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

Using MemCachier with Rails

Rails supports three types of caching: automatic whole site, per-view, and fragment. Refer to the Rails caching guide for more information on using MemCachier with Rails.

Add the Dalli gem and run bundle install as described in the above Ruby section. Once this gem is installed, configure the Rails cache_store appropriately. Modify your config/environments/production.rb with the following:

credentials = memcachier_servers = memcachier_username = memcachier_password = ''
if !ENV['VCAP_SERVICES'].blank?
  JSON.parse(ENV['VCAP_SERVICES']).each do |k,v|
    if !k.scan("memcachier").blank?
      credentials = v.first.select {|k1,v1| k1 == "credentials"}["credentials"]
      memcachier_servers = credentials["servers"]
      memcachier_username = credentials["username"]
      memcachier_password = credentials["password"]
    end
  end
end
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
                    }

Note: Rails.cache defaults to an in-memory store in your deployment environment, so it does not require a running memcached.

Testing from Rails

To test locally you can use the rails console:

rails console
>> Rails.cache.write('memcachier', 'clouds')
=> true
>> Rails.cache.read('memcachier')
=> 'clouds'

Using MemCachier with Python

MemCachier has been tested with the pylibmc memcache client. This client relies on the C libmemcached library, which you can install with your package manager on Linux or Windows. Once libmemcached is installed, install pylibmc:

$ pip install pylibmc

Be sure to update your requirements.txt file with the new pylibmc requirement. Your version might differ from the version in the below example.

pylibmc==1.4.0

Note: If you have difficulty installing the C libmemcached library or pylibmc, you can try python-binary-memcached. This is a pure python client that only supports Python 2 at this time.

Next, configure your settings.py file as the following example shows:

memcachier_service = json.loads(os.environ['VCAP_SERVICES'])['memcachier'][0]
credentials = memcachier_service['credentials']

servers = credentials('servers').split(',')
user = credentials('username')
pass = credentials('password')

mc = pylibmc.Client(servers, binary=True,
                    username=user, password=pass,
                    behaviors={"tcp_nodelay": True,
                               "ketama": True,
                               "no_block": True,})

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

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

Note: An error message you might 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 1 MB. MemCachier has a hard limit of 1 MB 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 1 MB and higher.

Using MemCachier with Node.js

For Node.js, we recommend the use of the memjs client library, which is written and supported by MemCachier. To install memjs, use node package manager (npm) as the following command shows:

$ npm install memjs

A new memjs client should be created to connect with MemCachier as follows:

var memjs = require('memjs');
var creds = JSON.parse(process.env.VCAP_SERVICES).memcachier[0].credentials;
var mc = memjs.Client.create(creds.servers, creds);

You can then test whether it works as follows:

mc.get('hello', function(val) {
  alert(val)
})

Using MemCachier with Java

For Java we recommend using the XMemcached client. There is also the SpyMemcached client which we have recommended in the past. Many MemCachier customers reported problems with SpyMemcached in the presence of network issues. SpyMemcached seems to have trouble coping with connection timeouts or resets. For this reason we now recommend XMemcached.

We also recommend using Apache Maven or Gradle as a build tool. Here we show the dependancy configuration for Maven but they are similar for Gradle. If you aren’t using Maven or Gradle and are instead using Apache Ant or your own build system, then simply add the xmemcached or spymemcached jar file as a dependency of your application.

XMemcached

To use XMemcached with Maven you need to add the xmemcached library to your dependencies in your pom.xml file:

<dependency>
  <groupId>com.googlecode.xmemcached</groupId>
  <artifactId>xmemcached</artifactId>
  <version>2.4.3</version>
</dependency>

Note: Please make sure to use at least version 2.4.3 of XMemcached as it contains important bug fixes.

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

import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.MemcachedClientBuilder;
import net.rubyeye.xmemcached.XMemcachedClientBuilder;
import net.rubyeye.xmemcached.auth.AuthInfo;
import net.rubyeye.xmemcached.command.BinaryCommandFactory;
import net.rubyeye.xmemcached.exception.MemcachedException;
import net.rubyeye.xmemcached.utils.AddrUtil;

import org.json.*;

import java.lang.InterruptedException;
import java.net.InetSocketAddress;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeoutException;

public class App {
  public static void main( String[] args ) {
    String vcap_services = System.getenv("VCAP_SERVICES");
    String memcachier_servers = "localhost:11211";
    String memcachier_username = "";
    String memcachier_password = "";

    if (vcap_services != null && vcap_services.length() > 0) {
        // parsing MemCachier credentials
        JSONObject root = new JSONObject(vcap_services);
        JSONArray mc = root.getJSONArray("memcachier");
        JSONObject credentials = mc.getJSONObject(0).getJSONObject("credentials");
        memcachier_servers = credentials.getString("servers");
        memcachier_username = credentials.getString("username");
        memcachier_password = credentials.getString("password");
    }

    List<InetSocketAddress> servers =
      AddrUtil.getAddresses(memcachier_servers.replace(",", " "));
    AuthInfo authInfo =
      AuthInfo.plain(memcachier_username, memcachier_password);

    MemcachedClientBuilder builder = new XMemcachedClientBuilder(servers);

    // Configure SASL auth for each server
    for(InetSocketAddress server : servers) {
      builder.addAuthInfo(server, authInfo);
    }

    // Use binary protocol
    builder.setCommandFactory(new BinaryCommandFactory());
    // Connection timeout in milliseconds (default: )
    builder.setConnectTimeout(1000);
    // Reconnect to servers (default: true)
    builder.setEnableHealSession(true);
    // Delay until reconnect attempt in milliseconds (default: 2000)
    builder.setHealSessionInterval(2000);

    try {
      MemcachedClient mc = builder.build();
      try {
        mc.set("foo", 0, "bar");
        String val = mc.get("foo");
        System.out.println(val);
      } catch (TimeoutException te) {
        System.err.println("Timeout during set or get: " +
                           te.getMessage());
      } catch (InterruptedException ie) {
        System.err.println("Interrupt during set or get: " +
                           ie.getMessage());
      } catch (MemcachedException me) {
        System.err.println("Memcached error during get or set: " +
                           me.getMessage());
      }
    } catch (IOException ioe) {
      System.err.println("Couldn't create a connection to MemCachier: " +
                         ioe.getMessage());
    }
  }
}

You may wish to look the xmemcached Wiki or JavaDocs.

SpyMemcached

To use SpyMemcached with Maven you need to add the spymemcached library to your dependencies in your pom.xml file:

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

Once your build system is configured, you can start adding caching to your Java app as shown in the following example:

import java.io.IOException;
import org.json.*;
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) {
    String vcap_services = System.getenv("VCAP_SERVICES");
    String memcachier_servers = "localhost:11211";
    String memcachier_username = "";
    String memcachier_password = "";

    if (vcap_services != null && vcap_services.length() > 0) {
        // parsing MemCachier credentials
        JSONObject root = new JSONObject(vcap_services);
        JSONArray mc = root.getJSONArray("memcachier");
        JSONObject credentials = mc.getJSONObject(0).getJSONObject("credentials");
        memcachier_servers = credentials.getString("servers");
        memcachier_username = credentials.getString("username");
        memcachier_password = credentials.getString("password");
    }
    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());
    }
  }
}

You might want to set the above code up as a new MemCachierClient class as shown in the following example:

package com.memcachier.examples.java;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;

import javax.security.auth.callback.CallbackHandler;

import net.spy.memcached.ConnectionFactory;
import net.spy.memcached.ConnectionFactoryBuilder;
import net.spy.memcached.MemcachedClient;
import net.spy.memcached.auth.AuthDescriptor;
import net.spy.memcached.auth.PlainCallbackHandler;

public class MemCachierClient extends MemcachedClient {

   public MemCachierClient(String username, String password, String servers) throws IOException {
       this(new SASLConnectionFactoryBuilder().build(username, password), getAddresses(servers));
   }

   public MemCachierClient(ConnectionFactory cf, List<InetSocketAddress> addrs) throws IOException {
       super(cf, addrs);
   }

   private static List<InetSocketAddress> getAddresses(String servers) {
       List<InetSocketAddress> addrList = new ArrayList<InetSocketAddress>();
       for (String server : servers.split(",")) {
           String addr = server.split(":")[0];
           int port = Integer.parseInt(server.split(":")[1]);
           addrList.add(new InetSocketAddress(addr, port));
       }
       return addrList;
   }
}

class SASLConnectionFactoryBuilder extends ConnectionFactoryBuilder {
   public ConnectionFactory build(String username, String password){
       CallbackHandler ch = new PlainCallbackHandler(username, password);
       AuthDescriptor ad = new AuthDescriptor(new String[]{"PLAIN"}, ch);
       this.setProtocol(Protocol.BINARY);
       this.setAuthDescriptor(ad);
       return this.build();
   }
}

Note: It is possible that you might run into Java exceptions about the class loader. See Spymemcached issue 155, which contains a suggested workaround.

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

Using MemCachier with Spring Boot

Note: We have written a tutorial on how to use build a Spring Boot application on Pivotal Web Services and scale it with Memcache here.

In order to use memcache in Spring you can use simple-spring-memcached. It works with both, the XMemcached (recommended) or the SpyMemcached client.

Simple Spring XMemcached

We recommend you use Simple Spring Memcached with the XMemcached client. In order to do so you need to add the respective dependencies to your pom.xml:

<dependency>
  <groupId>com.google.code.simple-spring-memcached</groupId>
  <artifactId>xmemcached-provider</artifactId>
  <version>4.0.0</version>
</dependency>
<dependency>
  <groupId>com.googlecode.xmemcached</groupId>
  <artifactId>xmemcached</artifactId>
  <version>2.4.3</version>
</dependency>

For version 4.0.0 of simple-spring-memcached it is important that you explicitly import XMemcached version 2.4.3 as it contains important bug fixes.

To configure Simple Spring Memcached with XMemcached, add the following configuration class to your application:

import java.net.InetSocketAddress;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import org.json.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.google.code.ssm.CacheFactory;
import com.google.code.ssm.config.AbstractSSMConfiguration;
import com.google.code.ssm.config.DefaultAddressProvider;
import com.google.code.ssm.providers.xmemcached.XMemcachedConfiguration;
import com.google.code.ssm.providers.xmemcached.MemcacheClientFactoryImpl;
import net.rubyeye.xmemcached.auth.AuthInfo;
import net.rubyeye.xmemcached.utils.AddrUtil;

@Configuration
public class MemCachierConfig extends AbstractSSMConfiguration {

  @Bean
  @Override
  public CacheFactory defaultMemcachedClient() {
    String vcap_services = System.getenv("VCAP_SERVICES");
    String memcachier_servers = "localhost:11211";
    String memcachier_username = "";
    String memcachier_password = "";

    if (vcap_services != null && vcap_services.length() > 0) {
        // parsing MemCachier credentials
        JSONObject root = new JSONObject(vcap_services);
        JSONArray mc = root.getJSONArray("memcachier");
        JSONObject credentials = mc.getJSONObject(0).getJSONObject("credentials");
        memcachier_servers = credentials.getString("servers");
        memcachier_username = credentials.getString("username");
        memcachier_password = credentials.getString("password");
    }

    String serverString = memcachier_servers.replace(",", " ");
    List<InetSocketAddress> servers = AddrUtil.getAddresses(serverString);
    AuthInfo authInfo = AuthInfo.plain(memcachier_username,
                                       memcachier_password);

    Map<InetSocketAddress, AuthInfo> authInfoMap =
      new HashMap<InetSocketAddress, AuthInfo>();
    for(InetSocketAddress server : servers) {
      authInfoMap.put(server, authInfo);
    }

    final XMemcachedConfiguration conf = new XMemcachedConfiguration();
    conf.setUseBinaryProtocol(true);
    conf.setAuthInfoMap(authInfoMap);

    final CacheFactory cf = new CacheFactory();
    cf.setCacheClientFactory(new MemcacheClientFactoryImpl());
    cf.setAddressProvider(new DefaultAddressProvider(serverString));
    cf.setConfiguration(conf);
    return cf;
  }
}

Now you can use the Simple Spring Memcached annotations in your Spring application.

Simple Spring SpyMemcached

If you want to use Simple Spring Memcached with SpyMemcached you need to add the respective dependencies to your pom.xml:

<dependency>
  <groupId>com.google.code.simple-spring-memcached</groupId>
  <artifactId>spymemcached-provider</artifactId>
  <version>4.0.0</version>
</dependency>

To configure Simple Spring Memcached with SpyMemcached, add the following configuration class to your application:

import org.json.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.google.code.ssm.CacheFactory;
import com.google.code.ssm.config.AbstractSSMConfiguration;
import com.google.code.ssm.config.DefaultAddressProvider;
import com.google.code.ssm.providers.spymemcached.SpymemcachedConfiguration;
import com.google.code.ssm.providers.spymemcached.MemcacheClientFactoryImpl;
import net.spy.memcached.auth.AuthDescriptor;
import net.spy.memcached.auth.PlainCallbackHandler;

@Configuration
public class MemCachierConfig extends AbstractSSMConfiguration {

  @Bean
  @Override
  public CacheFactory defaultMemcachedClient() {
    String vcap_services = System.getenv("VCAP_SERVICES");
    String memcachier_servers = "localhost:11211";
    String memcachier_username = "";
    String memcachier_password = "";

    if (vcap_services != null && vcap_services.length() > 0) {
        // parsing MemCachier credentials
        JSONObject root = new JSONObject(vcap_services);
        JSONArray mc = root.getJSONArray("memcachier");
        JSONObject credentials = mc.getJSONObject(0).getJSONObject("credentials");
        memcachier_servers = credentials.getString("servers");
        memcachier_username = credentials.getString("username");
        memcachier_password = credentials.getString("password");
    }

    AuthDescriptor ad = new AuthDescriptor(new String[] { "PLAIN" },
                new PlainCallbackHandler(memcachier_username,
                                         memcachier_password);

    final SpymemcachedConfiguration conf = new SpymemcachedConfiguration();
    conf.setUseBinaryProtocol(true);
    conf.setAuthDescriptor(ad);

    final CacheFactory cf = new CacheFactory();
    cf.setCacheClientFactory(new MemcacheClientFactoryImpl());
    cf.setAddressProvider(new DefaultAddressProvider(memcachier_servers));
    cf.setConfiguration(conf);
    return cf;
  }
}

Now you can use the Simple Spring Memcached annotations in your Spring application.

Use Simple Spring Memcached annotations

To apply caching to functions Simple Spring Memcached provides three main types of annotations:

  1. @ReadThrough*Cache tries to get a value from the cache. If it does not exist it will execute the function and store the return value in the cache to make sure it is available the next time the function is called.
  2. @Invalidate*Cache deletes key value pairs from the cache.
  3. @Update*Cache updates the values for stored keys.

Each type of annotation comes in 3 flavors (to replace the * above):

  1. Single applies the caching method to a single key that is specified by a parameter of the annotated function marked with the @ParameterValueKeyProvider annotation.
  2. Multi applies the caching method to a collection of keys and works the same as Single but the annotated parameter needs to be a Collection.
  3. Assign applies the caching method to an assigned key defined within the annotation.

These 9 annotations are the meat of Simple Spring Memacached but it offers more annotations to aid your caching needs. For more information consult the Simple Spring Memcached documentation.

Some examples

  • Probably the most used annotation is @ReadThroughSingleCache. It caches the result of complex computation with a key depending on the namespace and the input value. The cached value never expires.

    @ReadThroughSingleCache(namespace = "ComplexComuptation", expiration = 0)
    public ComplexSerializableResult compute(@ParameterValueKeyProvider Long input) {
      // ...
      return result;
    }
    
  • It is important to delete stale data and @InvalidateAssignCache does exactely that for a given key:

    @InvalidateAssignCache(namespace = "TableA", assignedKey = "SumOfColumnX")
    public void saveValueToTableA(TableAObject value) {
      //...
    }
    

More examples can be found in the Simple Spring Memcached documentation.

Use Spring Caching integration

Spring also has native caching annotations and simple-spring-memcached can be configured so Spring’s integrated caching is backed by memcache. While it is a good idea to use Spring’s caching integration if you want the flexibility to change the underlying store at any time, we generally recommend using the annotations provided by Simple Spring Memcached as they are specifically designed to be used with Memcache.

Enabling memcache for Spring’s cache integration requires an additional dependency in your pom.xml file:

<dependency>
  <groupId>com.google.code.simple-spring-memcached</groupId>
  <artifactId>spring-cache</artifactId>
  <version>4.0.0</version>
</dependency>

To use these annotations you need create a CacheManager bean and set the @EnableCaching annotation. Concretely, extend the MemCachierConfig shown above as follows:

// ...
import java.util.Arrays;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.CacheManager;
import com.google.code.ssm.Cache;
import com.google.code.ssm.spring.ExtendedSSMCacheManager;
import com.google.code.ssm.spring.SSMCache;

@EnableCaching
@Configuration
public class MemCachierConfig extends AbstractSSMConfiguration {

  @Bean
  @Override
  public CacheFactory defaultMemcachedClient() {
    // ...
  }

  @Bean
  public CacheManager cacheManager() throws Exception {
    // Use SSMCacheManager instead of ExtendedSSMCacheManager if you do not
    // need to set per key expiration
    ExtendedSSMCacheManager cacheManager = new ExtendedSSMCacheManager();
    Cache cache = this.defaultMemcachedClient().getObject();
    // SSMCache(cache, 0, false) creates a cache with default key expiration
    // of 0 (no expiration) and flushing disabled (allowClear = false)
    cacheManager.setCaches(Arrays.asList(new SSMCache(cache, 0, false)));
    return cacheManager;
  }
}

Now you can use Spring’s caching annotations, most importantly @Cacheble, @CacheEvict, and @CachePut.

Note: Spring’s annotations require a cache name. The default cache name configured by Simple Spring Memcached is `“default”`.

  • @Cacheable performs similarly to the @ReadThrough*Cache annotations explained above: it tries to get a value from the cache but if unavailable, it will execute the function and store the result for future calls to this function with the given parameters.

    @Cacheable("default#3600")
    public ComplexSerializableResult compute(Long input) {
      // ...
      return result;
    }
    

    @Cacheable does not have native support setting expiration times. However, if you use the ExtendedSSMCacheManager you can set an expriation time by appending #<seconds> to the cache name. The example above sets the expiration to one hour. Omitting this appendix falls back to the configured default expiration time.

  • @CacheEvict deletes a value from the cache. This is important to get rid of stale data.

    @CacheEvict("default")
    public void updateValue(ValueId id) {
      //...
    }
    
  • @CachePut allows you to add values to the cache and is a great way to optimize your cache. It supports the same options as the @Cacheable annotation.

    @CachePut("default")
    public Value updateValue(ValueId id) {
      //...
      return value;
    }
    

For more information on these caching annotations and their options consult Spring’s caching documentation and the Spring Caching Integration secion of the Simple Spring Memcached documentation.

Using MemCachier with PHP

First, install the PHPMemcacheSASL client. You can either obtain the code directly or use composer for package management. We suggest using composer.

If you are using composer, modify the 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;
$vcap_services = getenv("VCAP_SERVICES");
$creds = json_decode($vcap_services, true)["memcachier"][0]["credentials"]
// Create client
$m = new MemcacheSASL();
$servers = explode(",", $creds["servers"]);
foreach ($servers as $s) {
    $parts = explode(":", $s);
    $m->addServer($parts[0], $parts[1]);
}

// Setup authentication
$m->setSaslAuthData( getenv($creds["username"])
                   , getenv($creds["password"]) );

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

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 should not have any issues testing locally. Installation depends on your platform.

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

Once memcached has been installed, run it by executing the following comand:

$ memcached -v

Note: The examples below install memcached without SASL authentication support. This allows your client code to run without modification locally, since client code can still request SASL authentication. Memcached ignores the requests, effectively allowing any credentials.

On OS X

Installation on OS X uses Homebrew:

$ brew install memcached

On Ubuntu

$ sudo apt-get install memcached

Usage Analytics

Our analytics dashboard is a tool that gives you more insight into how you are using memcache. Here is a screenshot of the dashboard:

To access your application’s analytics dashboard, log in to your account and view one of your caches. The analytics displayed are the following:

  • 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.

  • 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 a Least Recently Used (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) versus 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 performed a flush command.

With the analytics dashboard we sample your cache once per hour. For more information on anaylytics, visit the MemCachier documentation.

Key-value Size Limit

MemCachier supports key-value objects up to 1 MB. This applies to both key-value pairs created through a set command and to existing key-value pairs extended with either an append or prepend command. In the latter case, the size of the key-value pair with the new data added must still be less than 1 MB. This limit applies to the combined size of the key and the value. For example, a key-value pair with a 512 KB key and a 712 KB value exceeds the limit.

A reason for this limit on key-value pair size is how MemCachier’s high performance design impacts memory management. It is also not standard practice to store values larger than 1 MB in a high-performance key-value store because the network transfer time limits performance. We recommend using a disk cache or a database for values larger than 1 MB.

New Relic integration

MemCachier supports integration with your New Relic dashboard if you are 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 set up the integration, you will need to find your New Relic license key. To do this, log in to New Relic, then click your New Relic username in the top right corner to access your Account Settings page. Your license key displays in the information column on the right side of the page. The key should be exactly 40 characters long. Please refer to the blog post for a visual walkthrough.

Once you have your New Relic license key, it can be entered for your cache on the analytics dashboard page. Click the button in the bottom right corner to do this.

Support

For support with your service instance, refer to the Contacting Service Providers for Support topic.

Submit all your MemCachier support or runtime issues to support@memcachier.com or our support site.

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

Additional Resources

MemCachier documentation

Create a pull request or raise an issue on the source for this page in GitHub