问题
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