Quick Start

 

Products & Services

 

Training Dates

US - San Francisco
Oct 6-7, 2010
Nov 11-12, 2010
Dec 2-3, 2010
Feb 4-5, 2011

India - Delhi
Dec 2-3, 2010

See training details.

 

Blogs & Tweets

Google App Engine How To

Why?

  • Speed - Ehcache cache operations take a few �s, versus around 60ms for Google's provided client-server cache, memcacheg.
  • Cost - Because it uses way less resources, it is also cheaper.
  • Object Storage - Ehcache in-process cache works with Objects that are not Serializable.

    We are planning an ehcache-googleappengine module which will integrate the speed of Ehcache with the scale of Google's Cache Infrastructure and provide the best of both worlds. Check http://ehcache.org regularly for updates.

Compatibility

Ehcache is compatible and works with Google App Engine.

Google App Engine provides a constrained runtime which restricts networking, threading and file system access.

Limitations

All features of Ehcache can be used except for the DiskStore and replication. Having said that, there are workarounds for these limitations. See the Recipes section below.

As of June 2009, Google App Engine appears to be limited to a heap size of 100MB. (See http://gregluck.com/blog/archives/2009/06/the_limitations.html for the evidence of this).

Versions

Version 1.6 and higher of Ehcache is compatible with Google App Engine.

Version 1.7.1 makes the CacheLoaders in Ehcache compatible with Google App Engine.

Older versions will not work.

Configuring ehcache.xml

Make sure the following elements are commented out:

  • diskStore path="java.io.tmpdir"/
  • cacheManagerPeerProviderFactory class= ../
  • cacheManagerPeerListenerFactory class= ../

    Within each cache element, ensure that:

  • overFlowToDisk=false or overFlowToDisk is omitted
  • diskPersistent=false or diskPersistent is omitted
  • no replicators are added
  • there is no bootstrapCacheLoaderFactory

    Copy and past this one to get started.

        <?xml version="1.0" encoding="UTF-8"?>
    
        <Ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:noNamespaceSchemaLocation="ehcache.xsd" >
    
            <cacheManagerEventListenerFactory class="" properties=""/>
    
            <defaultCache
                    maxElementsInMemory="10000"
                    eternal="false"
                    timeToIdleSeconds="120"
                    timeToLiveSeconds="120"
                    overflowToDisk="false"
                    diskPersistent="false"
                    memoryStoreEvictionPolicy="LRU"
                    />
    
            <!--Example sample cache-->
            <cache name="sampleCache1"
                   maxElementsInMemory="10000"
                   maxElementsOnDisk="1000"
                   eternal="false"
                   timeToIdleSeconds="300"
                   timeToLiveSeconds="600"
                   memoryStoreEvictionPolicy="LFU"
                    />
        </ehcache>

Recipes

Setting up Ehcache as a local cache in front of memcacheg

The idea here is that your caches are set up in a cache hierarchy. Ehcache sits in front and memcacheg behind. Combining the two lets you elegantly work around limitations imposed by Googe App Engine. You get the benefits of the �s speed of Ehcache together with the umlimited size of memcached.

Ehcache contains the hooks to easily do this.

To update memcached, use a CacheEventListener.

To search against memcacheg on a local cache miss, use cache.getWithLoader() together with a CacheLoader for memcacheg.

Using memcacheg in place of a DiskStore

In the CacheEventListener, ensure that when notifyElementEvicted() is called, which it will be when a put exceeds the MemoryStore's capacity, that the key and value are put into memcacheg.

Distributed Caching

Configure all notifications in CacheEventListener to proxy throught to memcacheg.

Any work done by one node can then be shared by all others, with the benefit of local caching of frequently used data.

Dynamic Web Content Caching

Google App Engine provides acceleration for files declared static in appengine-web.xml.

e.g.

    <static-files>
        <include path="/**.png" />
        <exclude path="/data/**.png" />
    </static-files>

You can get acceleration for dynamic files using Ehcache's caching filters as you usually would.

See the Web Caching chapter.

Google App Engine FAQ

I get an error java.lang.NoClassDefFoundError: java.rmi.server.UID is a restricted class

You are using a version of Ehcache prior to 1.6.