Java Reference
In-Depth Information
Listing 8-1. Servlet code for the Memcache API example
package com.kyleroche.gaeservices;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.cache.Cache;
import javax.cache.CacheException;
import javax.cache.CacheFactory;
import javax.cache.CacheManager;
import javax.cache.CacheStatistics;
import javax.servlet.http.*;
import com.google.appengine.api.memcache.MemcacheService;
import com.google.appengine.api.memcache.stdimpl.GCacheFactory;
@SuppressWarnings("serial")
public class GAEJ___AppEngine_ServicesServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/html");
Cache cache = null;
Map props = new HashMap();
props.put(GCacheFactory.EXPIRATION_DELTA, 3600);
props.put(MemcacheService.SetPolicy.ADD_ONLY_IF_NOT_PRESENT,
true);
try {
CacheFactory cacheFactory =
CacheManager.getInstance().getCacheFactory();
cache = cacheFactory.createCache(props);
} catch (CacheException e) {
resp.getWriter().println(e.getMessage());
}
Search WWH ::




Custom Search