zenmeso / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
0 stars 0 forks source link

Evict objects from Objectify cache #213

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. persist object through datastore
2. read it through Objectify, you get an old version
3. no way to ask objectify to evict the object from memory

What is the expected output? What do you see instead?
Expecting an api to notify objectify that the object is out of date

What version of the product are you using? On what operating system?
4.0, on gae

Please provide any additional information below.

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/6Xp99zReOK
QJ

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)

a copy of this was posted @ 
http://stackoverflow.com/questions/24502877/evict-objects-from-objectify-cache

Original issue reported on code.google.com by 1vue...@gmail.com on 1 Jul 2014 at 5:18

GoogleCodeExporter commented 9 years ago
As mentioned in the stackoverflow answer, you can workaround this immediately 
by directly deleting the cache entry from memcache. It's in the namespace 
`ObjectifyFactory.MEMCACHE_NAMESPACE` and the cache key is just the stringified 
(`toWebSafeString()`) version of the entity key.

Original comment by lhori...@gmail.com on 1 Jul 2014 at 6:15