Permalink
Browse files

defensive coding on the ImageProxy: if the store into the memcache fa…

…ils, we still go on to serve the original image
  • Loading branch information...
1 parent dca42ec commit 67f308707a42aeb056be33457af677ad35cf69ca Danny Yoo committed Jan 11, 2012
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/org/wescheme/servlet/ImageProxy.java
@@ -5,6 +5,7 @@
import javax.servlet.http.HttpServletResponse;
import com.google.appengine.api.memcache.Expiration;
+import com.google.appengine.api.memcache.MemcacheServiceException;
import com.google.appengine.api.memcache.MemcacheServiceFactory;
import com.google.appengine.api.memcache.MemcacheService;
@@ -54,13 +55,16 @@ public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOExce
ImageRecord record = getImageRecordFromCache(urlString);
if (record == null) {
record = createImageRecordFromNetwork(urlString);
- saveImageRecordToCache(record);
+ try {
+ saveImageRecordToCache(record);
+ } catch (MemcacheServiceException e) {
+ // If we can't save the image to the cache, just go on silently.
+ }
}
res.setContentType(record.contentType);
res.setHeader("Cache-Control", "public, max-age=300"); // 5 minutes on the browser
res.setHeader("Pragma", "public");
- // res.setContentLength(record.bytes.length);
res.getOutputStream().write(record.bytes);
} catch(ImageProxyException e) {
res.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());

0 comments on commit 67f3087

Please sign in to comment.