将对象保存在 MemCache 而不是 Datastore 中
我使用谷歌应用程序引擎构建了一个应用程序。该应用程序运行良好,但目前正在考虑对其进行优化,特别是我听说过将对象持久保存到memcache而不是数据存储的概念,作为快速访问经常需要的数据的一种方法。
假设我有这个模型的对象:
class Ea(db.Model):
name = db.StringProperty()
code = db.StringProperty()
并且我说过我想将以下实例保留在memcache中
myea = Ea.new(name='John',code='@jo')
我该怎么做?
I have built an app using google app engine. The app works fine, but am currently thinking of optimizing it, and in particular I've heard of this concept of persisting objects to memcache
instead of the datastore, as a means of quickly acessing frequently needed data.
Assume I have objects of this model:
class Ea(db.Model):
name = db.StringProperty()
code = db.StringProperty()
And I have say the following instance I want to keep in memcache
myea = Ea.new(name='John',code='@jo')
How do I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您关心数据,则应首先将其写入数据存储区。您可以使缓存预写入无效,然后根据您的应用程序,在写入后或第一次读取时重新缓存。
查看 Nick 关于高效内存缓存模型的帖子;他提出了一个很好的模式,并将帮助您避免一些常见问题。
If you care about the data, you should first write it to the datastore. You can invalidate the cache pre-write, then, depending on your application, recache post-write or on the first read.
Check out Nick's post on efficiently memcaching models; he presents a nice pattern, and will help you avoid some common issues.
Robert Kluin 指定的链接适用于基于数据库的模型。对于基于 ndb 的模型,您可以使用它。
The link specified by Robert Kluin works for db based model. For ndb based models you can use this.