Commit 2ed59fe2 authored by Jeffrey I. Schiller's avatar Jeffrey I. Schiller Committed by Gerrit Review System

Add the use of Memcache to the getMotd servlet to reduce the number of

queries to the datastore caused by the servlet. The cached lifetime is
currently hardcoded at 10 minutes.

Change-Id: Iec5d37966b836f2a7c52c19ceaeda28ea55859cf
parent ced6b4b1
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2010 Google Inc. All Rights Reserved.
package com.google.appinventor.server;
......@@ -10,7 +11,9 @@ import com.google.appinventor.shared.rpc.Motd;
import java.util.logging.Logger;
import com.google.appengine.api.memcache.MemcacheService;
import com.google.appengine.api.memcache.MemcacheServiceFactory;
import com.google.appengine.api.memcache.Expiration;
/**
* Implementation of the get motd service.
......@@ -31,6 +34,10 @@ public class GetMotdServiceImpl extends OdeRemoteServiceServlet implements GetMo
private final StorageIo storageIo = StorageIoInstanceHolder.INSTANCE;
private final MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
private final String motdcachekey = "c3c61e03-5f77-4107-8714-0d1faa3df325"; // UUID Generated by JIS
/**
* Gets the current Motd
*
......@@ -38,7 +45,14 @@ public class GetMotdServiceImpl extends OdeRemoteServiceServlet implements GetMo
*/
@Override
public Motd getMotd() {
return storageIo.getCurrentMotd();
Motd motd = (Motd) memcache.get(motdcachekey); // Attempt to use memcache to fetch it
if (motd != null)
return motd;
motd = storageIo.getCurrentMotd();
memcache.put(motdcachekey, motd, Expiration.byDeltaSeconds(600)); // Hold it for ten minutes
return motd;
}
/**
......
......@@ -3,13 +3,14 @@
package com.google.appinventor.shared.rpc;
import com.google.gwt.user.client.rpc.IsSerializable;
import java.io.Serializable;
/**
* Data Transfer Object representing motd.
*
* @author kerr@google.com (Debby Wallach)
*/
public class Motd implements IsSerializable, MotdProvider {
public class Motd implements IsSerializable, MotdProvider, Serializable {
private long id;
// Caption of the MOTD
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment