How to cache a link property in Google App Engine?
For example, let's say I have the following models:
class Many(db.Model):
few = db.ReferenceProperty(Few)
class Few(db.Model):
year = db.IntegerProperty()
Then I create a lot Manythat point to just one Few:
one_few = Few.get_or_insert(year=2009)
Many.get_or_insert(few=one_few)
Many.get_or_insert(few=one_few)
Many.get_or_insert(few=one_few)
Many.get_or_insert(few=one_few)
Many.get_or_insert(few=one_few)
Many.get_or_insert(few=one_few)
Now, if I want to iterate over everything Manyby reading their meaning Few, I would do the following:
for many in Many.all().fetch(1000):
print "%s" % many.few.year
The question arises:
- Will every access to
many.fewrun a database search? - If so, is it possible to cache somewhere, since only one search should be sufficient to simultaneously enter the same object?
As noted in one comment: I know about memcache, but I'm not sure how I can “enter it” when I call another object via a link.
memcache , , . memcache .