Evict objects from objectify cache

五迷三道 提交于 2019-12-24 21:31:28

问题


especially Objectify team,

I'm persisting my objects through this code pattern

Entity filled = ofy().save().toEntity(myPojo);
filled.setUnindexedProperty( "myStuff", "computedSpecialValue" );
datastore.persist(filled);

Reading back my objects, I noticed they are get from cache since Objectify was not notified that it should evict the updated entity from its cache.

I like the Objectify cache feature since it saves me the time to grab data from memcache and reconstuct the objects for each read, so I want my objects to be cached, but I want to be able to evict them.

This discussion says there was no solution in mid 2013, https://groups.google.com/forum/#!msg/objectify-appengine/n3FJjnYVVsk/6Xp99zReOKQJ

If it's still the case, I'd expect an API like

ofy().save().entity(myPojo).evict();

and by the way, I imagine the API would be more consistent if

Entity filled = ofy().save().toEntity(myPojo);

was replaced by

Entity filled = ofy().save().entity(myPojo).toEntity();

Naturally, there's a costly workaround to the issue:

  • save the entity twice (once manually, then through objectify)

回答1:


While there is no formal API for evicting cache entries, it's not hard to do:

MemcacheServiceFactory
    .getMemcacheService(ObjectifyFactory.MEMCACHE_NAMESPACE)
    .delete(key.toWebSafeString());


来源:https://stackoverflow.com/questions/24502877/evict-objects-from-objectify-cache

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!