Appengine Memcache Service : Google Cloud Platform

Color Orange
Google Cloud - Community
2 min readJun 17, 2016

Memcache is one of the great service for designing high performance scalable applications on Appengine.

Memcache basically provides you facility to cache your data in-memory, and it is super fast store and retrieve. One of the use case of memory cache is to speed up your database operation, so when you have to read some data frequently from DB that doesn’t change often then you can put this in memcache and save your database hits.

Things that you know about Memcache

  • Two type of Memcache storage available : 1. Shared ( free ) 2. Dedicated ( paid)
  • The basic difference in Shared & Dedicated cache is that the shared cache operation does not guarantee capacity and performance, and Dedicated cache charges on per GB per Hour rate ( but rate is very low, read here )
  • The Maximum size of a cached data value is 1MB
  • Memcache Key can not be larger than 250 bytes
  • Memcache can not contain a null byte
  • Two type of API available for Memcache usage : Low Level Memcache API and JCache Specification ( with some limitation )
  • I recommend to use Low Level API since it offers more features such as enhanced statistics, asynchronous operations etc.
  • You can set expiry time for your memcache key-value pair
  • You can store Strings, Boolean, Integers, Objects etc. in memcache

Memcache Statistics Console

As shown in above screenshot you can see, its a free shared memcache that I have used and you can also see Hit ratio, Total items, Oldest item and Total cache size.

With “New Key” you can create new key-value pair directly from UI ( awesome ), “Flush Cache” will remove all key-value pairs from cache, this is very useful when you want to clear all your cache, no need to write any code.

Some code to give you a kick start (Java)

In Above example I have illustrated how you can add and retrieve object in memcache with expiration time. You can use normal or async memcache service as per your need.

I have been using memcache a lot while designing Appengine applications. I used both free and dedicated cache, both are great in terms of performance. Objectify for Google’s Cloud Datastore also uses Memcache internally for caching mechanism. As a conclusion memcache is highly recommended and must consider while designing your application.

Official Site

Memcache Best Practice Guide

--

--