1
votes

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!

2

2 Answers

2
votes

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

1
votes

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