Using Memcache

This page describes how to configure and monitor the memcache service for your application using the Google Cloud Platform Console. It also describes how to use the App Engine Memcache PHP API to set and retrieve cached values. To learn more about memcache, read the Memcache Overview.

Configuring memcache

  1. Go to the Memcache page in the Google Cloud Platform Console.
    Go to the Memcache page
  2. Select the memcache service level you want to use:

    • Shared (default) - free and provides cache capacity on a best-effort basis.
    • Dedicated - billed by the GB-hour of cache size and provides a fixed cache capacity assigned exclusively to your application.

    Learn more about available service classes in Memcache Overview.

Caching and retrieving values

Caching a value

Use Memcache::set to add a key's value:

$memcache = new Memcache;
$value = $request->getContent();
return $memcache->set($key, $value);

Looking up cached values

Use Memcache::get to look up the value of a single key:

$memcache = new Memcache;
return $memcache->get($key);

Monitoring memcache in the Google Cloud Platform Console

  1. Go to the Memcache page in the Google Cloud Platform Console.
    Go to the Memcache page
  2. Look at the following reports:
    • Memcache service level: Shows if your application is using the Shared or Dedicated service level. If you are an owner of the project, you can switch between the two. Learn more about the service levels.
    • Hit ratio: Shows a percentage and the raw number of memcache hits and misses.
    • Items in the cache.
    • Oldest item age: The age of the oldest cached item. Note that the age of an item is reset every time it is used, either read or written.
    • Total cache size.
  3. You can take any of the following actions:

    • New key: Add a new key to the cache.
    • Find a key: Retrieve an existing key.
    • Flush cache: Remove all the key-value pairs from the cache.
  4. (Dedicated memcache only) Look through the list of Hot keys.

    • "Hot keys" are keys that receive more than 100 queries per second (QPS) in the memcache.
    • This list includes up to 100 hot keys, sorted by highest QPS.
    • Read the article Best Practices for App Engine Memcache for tips on how to distribute load more evenly across the keyspace.

What's next

Send feedback about...

App Engine standard environment for PHP