Google App Engine 中的查找表需要模式
我正在使用 Google App Engine 和 Datastore 的 Python 版本。加载包含查找数据的表的好方法是什么?
通过查找数据,我的意思是在初始加载后,不需要插入、删除或更新任何行
如果清除所有行并重新加载表会破坏引用它的其他行的引用完整性,则这是不可接受的。
这是我正在使用的几种类型的示例,我想将查找数据加载到其中
class Badge(db.Model): name = db.StringProperty() level = db.IntegerProperty() class Achievement(db.Model): name = db.StringProperty() level = db.IntegerProperty() badge = db.ReferenceProperty(reference_class=Badge)
这是一种不保存查找数据但引用它的示例,
class CamperAchievement(db.Model): camper = db.ReferenceProperty(reference_class=Camper) achievement = db.ReferenceProperty(reference_class=Achievement) session = db.ReferenceProperty(reference_class=Session) passed = db.BooleanProperty(default=True)
我希望找出两件事:
加载数据的代码应该是什么样的?
什么应该触发加载代码执行?
I'm using the Python version of Google App Engine and Datastore. What is a good way to load a table that will contain lookup data?
By look up data I mean that after the initial load no rows will need to be inserted, deleted, or updated
Blowing away all rows and reloading the table is not acceptable if it destroys referential integrity with other rows referring to it.
Here is an example of a couple kinds that I am using that I want to load lookup data into
class Badge(db.Model): name = db.StringProperty() level = db.IntegerProperty() class Achievement(db.Model): name = db.StringProperty() level = db.IntegerProperty() badge = db.ReferenceProperty(reference_class=Badge)
Here is an example of a kind not holding look up data but referring to it
class CamperAchievement(db.Model): camper = db.ReferenceProperty(reference_class=Camper) achievement = db.ReferenceProperty(reference_class=Achievement) session = db.ReferenceProperty(reference_class=Session) passed = db.BooleanProperty(default=True)
I'm looking to find out two things:
What should the code to load the data look like?
What should trigger the loading code to execute?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果它确实创建一次并且在部署的生命周期内永远不会更改,并且它相对较小(几兆或更小),请将其作为数据文件与您的应用程序一起存储。让应用程序首先将数据加载到内存中,并将其缓存在那里。
If it's really created once and never changes within the lifetime of a deployment, and it's relatively small (a few megs or less), store it with your app as data files. Have the app load the data into memory initially, and cache it there.
我认为您指的是某种后写式缓存,但从您的问题来看并不清楚。
这是一种常见的模式,用于从慢速源(如数据库/磁盘)读取数据并将其缓存在快速源(如内存缓存/内存)中以便稍后快速检索。当情况发生变化时,您有责任清空所有缓存的项目。
请参阅使用 memcache 的第一个示例
I think you're referring to some kind of write-behind cache but it is not really that clear from your question.
This is a common pattern for reading data slow a slow source (like a database/disk) and caching it in a fast source (like memcache/memory) for quick retrieval later. It is then your responsibility to empty out all the cached items when things change.
See the first example on Using memcache