views:

43

answers:

2

Hello,

In Python, say I've got a model of class A that has a ReferenceProperty b to model class B, which has a ReferenceProperty c to model class C.

Assuming an instance of A already exists in the datastore, I can get it by saying:

q = A.all()
a = q.get()

In this scenario, how does entity loading work? Is a.b retrieved when a is retrieved? Is a.b.c retrieved when a.b is retrieved? Are b and c retrieved only when they are first accessed? If I were to store a in memcache, would b and c also be stored? If not, when would they be retrieved when I get a back out of memcache?

The reason I'm asking these questions (besides curiosity) is because I have an entity which I'd like to store in memcache, but it links to another entity (which links to another entity, etc.), and the total size of the linked entities may be more than 1MB.

Thanks!

+1  A: 

ReferenceProperties are lazily-loaded. b will not be looked up from the datastore until you actually use it for something.

Adam Crossland
+1  A: 

The models will be dereferenced when you first access them. So calling a.b will get b, and calling a.b.c will get c.

Have a look at Nick Johnson's blog for some tips about memcahing models: http://blog.notdot.net/2009/9/Efficient-model-memcaching

Robert Kluin
Here is some additional discussion on pickle vs proto_buf: http://groups.google.com/group/google-appengine/browse_thread/thread/f91ec576cddc75de/5a6b0d8ea28e02a1
Robert Kluin
Ah yes, I heard about the pickle-vs-pb thing. I wonder how fast it is to pickle a plain string?
Cameron
In my tests, pickling a string is significantly (a factor of 10) faster than pickling a very simple model instance.
Robert Kluin