Cover by Dan Sanderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

The Java Memcache API

As with other services, App Engine includes two Java interfaces to the memcache service. One is a proprietary interface that provides direct access to the features of the service. The other is an implementation of JCache, an interface standard proposed by JSR 107.

As of this writing, JSR 107 is not a ratified standard, and the recommended way to use it on App Engine is in flux. So for now, we’ll just consider the proprietary interface. For more information on using the JCache interface with App Engine, consult the App Engine documentation.

The memcache service Java API allows for the use of any serializable object as the key or the value of a key-value pair stored in the cache. Keys whose serialized form is larger than 250 bytes are hashed to 250 bytes. Values can be up to one megabyte in size.

In many cases, you can make a JPA data class serializable simply by declaring that the class implements Serializable, with no other changes. If you’re using the low-level datastore API, the Entity class and all of the property value classes implement the Serializable interface.

With App Engine’s memcache service Java API, you interact with the service using a MemcacheService object, which you get from MemcacheServiceFactory.getMemcacheService(). The basic operations are available as methods of MemcacheService: put(), get(), and delete().

import com.google.appengine.api.memcache.MemcacheService; import com.google.appengine.api.memcache.MemcacheServiceFactory; // ... List<String> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required