Objectify save而不打Memcache

时间:2017-10-12 15:53:48

标签: google-app-engine memcached objectify

我的实体是@Cache d,那很好。

但是,对于一个cron工作,我希望ofy().save.entities()接触Memcache。原因是,我保存了数以千计的物品,并且我不需要它们进行检索。

此外,我不断得到奇怪的例外,例如:

java.lang.reflect.InvocationTargetException
at com.google.appengine.runtime.Request.process-326a59f97d0f0252 (Request.java)
at sun.reflect.GeneratedMethodAccessor21.invoke (Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:42)
at com.googlecode.objectify.cache.MemcacheServiceRetryProxy.invoke (MemcacheServiceRetryProxy.java:68)
at com.sun.proxy.$Proxy9.putAll (Unknown Source)
at com.googlecode.objectify.cache.KeyMemcacheService.putAll (KeyMemcacheService.java:91)
at com.googlecode.objectify.cache.EntityMemcache.empty (EntityMemcache.java:323)
at com.googlecode.objectify.cache.CachingAsyncDatastoreService$5.trigger (CachingAsyncDatastoreService.java:445)
at com.googlecode.objectify.cache.TriggerFuture.isDone (TriggerFuture.java:87)
at com.googlecode.objectify.cache.TriggerFuture.get (TriggerFuture.java:102)
at com.googlecode.objectify.cache.PendingFutures.completeAllPendingFutures (PendingFutures.java:57)
at com.googlecode.objectify.ObjectifyService$2.close (ObjectifyService.java:120)
at com.googlecode.objectify.ObjectifyFilter.doFilter (ObjectifyFilter.java:49)

com.google.appengine.api.memcache.MemcacheServiceException: Memcache putAll: Unknown exception setting 2 keys
at com.google.appengine.api.memcache.MemcacheServiceApiHelper$RpcResponseHandler.handleApiProxyException (MemcacheServiceApiHelper.java:69)
at com.google.appengine.api.memcache.AsyncMemcacheServiceImpl$RpcResponseHandlerForPut.handleApiProxyException (AsyncMemcacheServiceImpl.java:349)
at com.google.appengine.api.memcache.MemcacheServiceApiHelper$1.absorbParentException (MemcacheServiceApiHelper.java:111)
at com.google.appengine.api.utils.FutureWrapper.handleParentException (FutureWrapper.java:52)
at com.google.appengine.api.utils.FutureWrapper.get (FutureWrapper.java:91)
at com.google.appengine.api.utils.FutureWrapper.get (FutureWrapper.java:89)
at com.google.appengine.api.memcache.MemcacheServiceImpl.quietGet (MemcacheServiceImpl.java:26)
at com.google.appengine.api.memcache.MemcacheServiceImpl.putAll (MemcacheServiceImpl.java:115)
at com.googlecode.objectify.cache.KeyMemcacheService.putAll (KeyMemcacheService.java:91)
at com.googlecode.objectify.cache.EntityMemcache.getAll (EntityMemcache.java:242)
at com.googlecode.objectify.cache.CachingAsyncDatastoreService.get (CachingAsyncDatastoreService.java:252)

com.google.appengine.api.memcache.MemcacheServiceException: Memcache getAll: exception getting multiple keys
at com.google.appengine.api.memcache.MemcacheServiceApiHelper$RpcResponseHandler.handleApiProxyException (MemcacheServiceApiHelper.java:69)
at com.google.appengine.api.memcache.MemcacheServiceApiHelper$1.absorbParentException (MemcacheServiceApiHelper.java:111)
at com.google.appengine.api.utils.FutureWrapper.handleParentException (FutureWrapper.java:52)
at com.google.appengine.api.utils.FutureWrapper.get (FutureWrapper.java:91)
at com.google.appengine.api.memcache.MemcacheServiceImpl.quietGet (MemcacheServiceImpl.java:26)
at com.google.appengine.api.memcache.MemcacheServiceImpl.getAll (MemcacheServiceImpl.java:64)
at com.googlecode.objectify.cache.KeyMemcacheService.getAll (KeyMemcacheService.java:83)
at com.googlecode.objectify.cache.EntityMemcache.cacheGetAll (EntityMemcache.java:365)
at com.googlecode.objectify.cache.EntityMemcache.putAll (EntityMemcache.java:296)
at com.googlecode.objectify.cache.CachingAsyncDatastoreService$3.success (CachingAsyncDatastoreService.java:279)
at com.googlecode.objectify.cache.CachingAsyncDatastoreService$3.success (CachingAsyncDatastoreService.java:268)

所以,我的问题是,如何使用Objectify保存而不打Memcache?

和/或,我该如何防止这些异常发生?

2 个答案:

答案 0 :(得分:3)

你可以使用ofy().cache(false),但你必须要小心。

在保存时,Objectify清除缓存条目。在加载时,Objectify检查memcache,如果该值不存在,则将其保存在memcache中以供日后使用。通常,您希望保存此清除行为,否则您可能会在缓存中留下陈旧条目。在批量加载很少访问的实体时,使用ofy().cache(false).load()...并且memcache将保持未受污染。

或者只是从实体类中删除@Cache

我不知道该怎么说你的例外;它来自GAE的肠子而不是Objectify。

答案 1 :(得分:1)

您可以禁用操作的全局缓存:

ofy().cache(false).save()...

更多详情here