Re: Few questions from a newcomer regarding Global cache

63 views
Skip to first unread message

Alex

unread,
Mar 14, 2013, 3:50:37 AM3/14/13
to objectify...@googlegroups.com
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

Mat Jaggard

unread,
Mar 14, 2013, 4:41:31 AM3/14/13
to objectify...@googlegroups.com
Regarding your third question, outside of a transaction, Objectify will indeed do a keys-only query followed by 10 memcache operations (one of which will be followed by a datastore get).

Your final question is actually quite tricky. Alex was right in saying that there shouldn't be any problems, however Objectify does some munging of names for embedded entities, for collections of non-native datastore entites and for polymorphic entities. You can see what these are on this page:

I don't know what JDO does with these types of things but it might or might not be possible to make Objectify load and save in exactly the same format.


--
You received this message because you are subscribed to the Google Groups "objectify-appengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to objectify-appen...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jeff Schnitzer

unread,
Mar 14, 2013, 5:36:36 AM3/14/13
to objectify...@googlegroups.com
Just catching up on these questions... been on airplanes and in
meetings for a preposterous number of hours today, if my answers are
wrong it's probably because I'm hallucinating. Sorry in advance.

Mat and Alex have it right (as usual). To recap:

* Load-by-key operations will skip the datastore if the data
(existence or negative existence) is in memcache.
* There is no strongly consistent test-for-existence operation that
is cheaper/better than load-by-key.
* If your entities have the @Cache annotation, Objectify by default
converts all queries to keys-only plus get-by-key. This could be good
or bad depending on your app; we speculate probably good. You can
explicitly define the behavior with hybrid(boolean).
* JDO doesn't really have an equivalent to Objectify's @Embed
collections. You should have no trouble going from JDO to Objectify,
but if you use Ofy's advanced features, you might have trouble going
back.

Jeff

Eurig Jones

unread,
Mar 16, 2013, 8:43:50 AM3/16/13
to objectify...@googlegroups.com, je...@infohazard.org
Thanks a lot for your help.

I've managed to successfully get JDO and Objectify working with the same entity objects which means i can migrate in small chunks which is great.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "objectify-appengine" group.
> To unsubscribe from this group and stop receiving emails from it, send an
Reply all
Reply to author
Forward
0 new messages