Google App Engine 中的引用模型加载
在Python中,假设我有一个类A
的模型,它有一个ReferencePropertyb
来建模类B
,它有一个ReferenceProperty>c
到模型类 C
。
假设数据存储中已经存在 A
的实例,我可以通过说:
q = A.all()
a = q.get()
在这种情况下,实体加载如何工作?检索a
时是否检索到ab
?检索ab
时是否检索到abc
? b
和 c
仅在首次访问时才检索吗?如果我将a
存储在memcache中,b
和c
也会被存储吗?如果没有,当我从内存缓存中取回a
时,什么时候会检索它们?
我问这些问题的原因(除了好奇之外)是因为我有一个想要存储在内存缓存中的实体,但它链接到另一个实体(链接到另一个实体等),并且它的总大小链接的实体可能超过 1MB。
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您第一次访问模型时,它们将被取消引用。所以调用ab会得到b,调用abc会得到c。
请参阅 Nick Johnson 的博客,了解有关 memcaching 模型的一些提示:
http://blog.notdot.net/2009/9/Efficient-model-内存缓存
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
ReferenceProperties 是延迟加载的。 b 不会从数据存储中查找,直到您实际将其用于某些用途。
ReferenceProperties are lazily-loaded. b will not be looked up from the datastore until you actually use it for something.