我正在使用Google Apps Engine SDK 1.9.12在本地测试一些代码。我添加了一个servlet监听器来初始化带有2个命名空间的memcache。我在方法contextDestroyed(ServletContextEvent sce)
中添加了代码以清除Memcache条目:
MemcacheServiceFactory.getMemcacheService().clearAll();
这实际上会引发以下异常并且服务器已关闭:
WARNING: EXCEPTION
com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'memcache' or call 'FlushAll()' was not found.
at com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:179)
at com.google.apphosting.api.ApiProxy$1.get(ApiProxy.java:177)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:88)
at com.google.appengine.api.memcache.MemcacheServiceImpl.quietGet(MemcacheServiceImpl.java:26)
at com.google.appengine.api.memcache.MemcacheServiceImpl.clearAll(MemcacheServiceImpl.java:170)
at com.valeo.general.util.BaseCacheManager.clearAll(BaseCacheManager.java:47)
at com.valeo.general.listeners.BaseCacheListener.contextDestroyed(BaseCacheListener.java:27)
at org.mortbay.jetty.handler.ContextHandler.doStop(ContextHandler.java:599)
at org.mortbay.jetty.webapp.WebAppContext.doStop(WebAppContext.java:505)
at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
at org.mortbay.jetty.handler.HandlerWrapper.doStop(HandlerWrapper.java:142)
at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
at com.google.appengine.tools.development.JettyContainerService.reloadWebApp(JettyContainerService.java:393)
at com.google.appengine.tools.development.JettyContainerService$2.filesChanged(JettyContainerService.java:380)
at org.mortbay.util.Scanner.reportBulkChanges(Scanner.java:486)
at org.mortbay.util.Scanner.reportDifferences(Scanner.java:352)
at org.mortbay.util.Scanner.scan(Scanner.java:280)
at org.mortbay.util.Scanner$1.run(Scanner.java:232)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
请帮我解决这个问题。
答案 0 :(得分:0)
当App Engine Java框架在contextDestroyed(ServletContextEvent)
中调用您的代码时,它已经拆除了与后端服务的连接,包括memcache。
很遗憾,您无法使用ServletContextListener
在关机时执行内存缓存操作。