String url_with_hash_fragment = uri
+ rewriteQueryString(queryString);
// check memcache first
Cache cache = null;
String pageSource = null;
Map<Object, Object> props = new HashMap<Object, Object>();
props.put(GCacheFactory.EXPIRATION_DELTA, new Integer(3600));
try {
cache = CacheManager.getInstance().getCacheFactory()
.createCache(props);
// Get the value from the cache.
pageSource = (String) cache.get(url_with_hash_fragment);
} catch (CacheException e) {
// ...
}
// ////////////
if (pageSource == null) {
// use the headless browser to obtain an HTML snapshot
URL url = new URL(SCHEME, domain, port, url_with_hash_fragment);
this.webClient.getOptions().setTimeout(0);
HtmlPage page = null;
try {
page = this.webClient.getPage(url);
// gae hack because its single threaded
this.webClient.getJavaScriptEngine().pumpEventLoop(
PUMP_TIME);
} catch (IOException ioe) {
Logger.getLogger("")
.warning(
"Failed to let google index "
+ url
+ " Work on increasing server side performance.");
}
if (page != null) {
pageSource = page.asXml();
}
}
ServletOutputStream out = response.getOutputStream();
out.println(new String(pageSource));
out.flush();
// update cache
if (cache != null) {
cache.put(url_with_hash_fragment, pageSource);
}
} else {
try {
/*
* not an _escaped_fragment_ URL, so move up the chain of