Appengine: link caching property?

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 .

+3
2

- - , . , , , - , .

, , . , ReferenceProperties.

, : , :

keys = [MyModel.ref.get_value_for_datastore(x) for x in referers]
referees = db.get(keys)

, , db ( memcache). , . , : , , .

+8

:

  • many.few ? . , 1 2
  • , -, ? memcache. google.appengine.api.memcache.

memcache http://code.google.com/appengine/docs/python/memcache/usingmemcache.html

+1

Source: https://habr.com/ru/post/1713385/


All Articles