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.
......@@ -24,13 +27,17 @@ public class GetMotdServiceImpl extends OdeRemoteServiceServlet implements GetMo
// Logging support
private static final Logger LOG = Logger.getLogger(GetMotdServiceImpl.class.getName());
// The value of this flag can be changed in appengine-web.xml
private static final Flag<Integer> motdCheckIntervalSecs =
private static final Flag<Integer> motdCheckIntervalSecs =
Flag.createFlag("motd.check.interval.secs", 300);
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,9 +45,16 @@ 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;
}
/**
* Returns the value, in seconds, of the motd.check.interval.secs flag.
* 0 means don't check 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
......@@ -87,7 +88,7 @@ public class Motd implements IsSerializable, MotdProvider {
Motd motd = (Motd) obj;
if (!motd.getCaption().equals(this.caption)) return false;
if (!(motd.hasContent() == this.hasContent())) return false;
return motd.hasContent() ? motd.getContent().equals(this.content) : true;
return motd.hasContent() ? motd.getContent().equals(this.content) : true;
}
@Override
......
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