For Q1: If inside a transaction I believe it will still go to the datastore (requirement of transactions or some such). If transactionless, my understanding is that it will use memcache only if it can.
Q2: I vaguely remember someone asking for this before, and I think you need to use low-level memcache API.
If you're concerned regarding Q1 (unnecessary datastore hit), doing the operation as transactionless will just grab it from memcache without touching the datastore if it can.
Also, since memcache is free it's not like it costs anything anyway - the biggest delay is the API call itself and not the entity retrieval (i.e. effectively same time for query or get).
I'm not entirely sure about Q3, but for memory, a filter will always go to the datastore... Having said that, it'd be nice if it grabbed from memcache where possible, but I don't think it quite works like that or something (I may be wrong on this).
I should say that I tend not to worry about these sorts of things (feels too much like micro optimizations) so some parts might be a bit off.
However in the end, Objectify will use the memcache when it can, and the datastore when it can't.
Hence, so long as you use transactions only where you need them, and transactionless the rest of the time, then there's not much else to be done about it with regards to this kind of optimization.
Oh, and with regards to final question - there
shouldn't be any problems running both on same entity (assuming annotations don't clash - which I don't think they can anymore since Ofy has its own annotations now).
Regards,
Alex
On Thursday, 14 March 2013 01:18:52 UTC+10:30, Eurig Jones wrote:
I'm currently porting an app from JDO master/slave app engine to using Objectify to lower costs via the benefit of the built-in memcache based global cache of Objectify.
I've started moving some of the queries and I have a few (possibly basic) questions that I cannot find the answer to.
Code Snippet 1
public static boolean userExists(String username)
{
Player pl = OfyService.ofy().load().type(Player.class).id(username).get();
return pl != null;
}
- Question 1: Regarding above code. Will this method touch the datastore at all if the Player object is in memcache?
- Question 2: Is it possible to change the above code so it simply checks for the existence of the player and not fetch the whole object?
Code Snippet 2
public static Player getUserByType(String type)
{
return OfyService.ofy().load().type(Player.class).filter("type", type).list();
}
- Question 3: There is 10 of these Player objects in the datastore, and 9 of them in memcache. Am I right in saying that it will do a keys-only query to get the 10 keys, then fetch the 9 objects fromi memcache, then get the last one from the datastore and memcache it?
Final Question: I'm converting my entities from JDO to Objectify as mentioned and I have a lot of queries! Is it possible somehow to have JDO and Objectify running side by side for the same entity? Or would I need a duplicate copy of the entity class with different annotations?
Thanks a lot!
Eurig