PrintWriter out = resp.getWriter();
List<String> headlines =
new ArrayList<String>(Arrays.asList("...", "...", "..."));
MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
memcache.put("headlines", headlines);
headlines = (List<String>) memcache.get("headlines");
memcache.delete("headlines");
memcache.put("headlines", headlines,
Expiration.byDeltaSeconds(300));
memcache.put("headlines", headlines, null,
SetPolicy.ADD_ONLY_IF_NOT_PRESENT);
boolean headlinesAreCached = memcache.contains("headlines");
memcache.put("tempnode91512", "...");
memcache.delete("tempnode91512", 5);
memcache.put("tempnode91512", "..."); // fails within the 5 second add-lock
Map<Object, Object> articleSummaries = new HashMap<Object, Object>();
articleSummaries.put("article00174", "...");
articleSummaries.put("article05234", "...");
articleSummaries.put("article15280", "...");
memcache.putAll(articleSummaries);
List<Object> articleSummaryKeys = Arrays.<Object>asList(
"article00174",
"article05234",
"article15820");
articleSummaries = memcache.getAll(articleSummaryKeys);
memcache.deleteAll(articleSummaryKeys);
// The new interface for memcache namespaces declares the
// namespace when constructing the MemcacheService.
MemcacheService memcacheNews = MemcacheServiceFactory.getMemcacheService("News");
memcacheNews.put("headlines", headlines);
MemcacheService memcacheUser = MemcacheServiceFactory.getMemcacheService("User");
List<String> userHeadlines =
new ArrayList<String>(Arrays.asList("...", "...", "..."));
memcacheUser.put("headlines", userHeadlines);
// Get User:"headlines"
userHeadlines = (List<String>) memcacheUser.get("headlines");
// Get News:"headlines"
headlines = (List<String>) memcacheNews.get("headlines");
memcache.put("work_done", 0);