I am developing in Google App Engine since one year ago and I am understanding how important is the warmup time for instances. So I ended up with an idea: is it possible to cache singleton in memcache? For example I am using the singleton pattern for JDO PersistenceManagerFactory.
Here is my actual code (as described in documentation):
private static PersistenceManagerFactory pmfInstance = JDOHelper.getPersistenceManagerFactory(<my-name>);
Does it have any sense something like extend the JDOHelper and write a function like this one:
public static PersistenceManagerFactory getPersistenceManagerFactoryCached(String name) {
MemcacheService cache = MemcacheServiceFactory.getMemcacheService();;
PersistenceManagerFactory staticPMF= null;
if (cache.contains("JDO_PMF")) {
staticPMF = (PersistenceManagerFactory) cache.get("JDO_PMF");
} else {
staticPMF = JDOHelper.getPersistenceManagerFactory(name);
cache.put("JDO_PMF", staticPMF);
}
return staticPMF;
}
My idea should be to cache the PersistenceManagerFactory to speed-up the first instance and then use this one as the singleton:
private static PersistenceManagerFactory pmfInstance = JDOHelperCached.getPersistenceManagerFactory(<my-name>);