如何使用金字塔进行缓存?
我查看了文档,但没有看到(乍一看)有关 Pyramid 中缓存的任何内容。也许我错过了一些东西......或者也许有一些第三方软件包可以帮助解决这个问题。
例如,如何缓存数据库查询(SQLAlchemy),如何缓存视图?谁能提供一些示例或文档的链接?
感谢任何帮助!
编辑:
如何使用内存缓存或数据库类型缓存或基于文件的缓存?
I've looked in the documentation and haven't seen (from first sight) anything about cache in Pyramid. Maybe I missed something... Or maybe there are some third party packages to help with this.
For example, how to cache db query (SQLAlchemy), how to cache views? Could anyone give some link to examples or documentation?
Appreciate any help!
EDITED:
How to use memcache or database type cache or filebased cache?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该安装pyramid_beaker。
然后阅读 烧杯 文档。默认情况下,它使用基于内存的缓存,但它可以轻松支持 memcached 和基于文件的缓存。
You should install pyramid_beaker.
Then read the beaker documentation. By default it uses memory based cache, but it can easily support memcached and filebased cache.
您的选择是pyramid_beaker 和dogpile.cache
Pyramid_beaker 是为会话提供烧杯缓存而编写的。它还允许您配置烧杯缓存区域,可以在其他地方使用。
dogpile.cache 是烧杯的替代品。它尚未集成以提供会话支持或基于environment.ini 的设置。然而,它解决了烧杯的许多杂项问题和缺点。
您不能/不应该缓存 SqlAlchemy 查询或结果。奇怪和糟糕的事情将会发生,因为 SqlAlchemy 对象绑定到数据库会话。最好将 sqlalchemy 结果转换为另一个对象/字典并缓存它们。
Your options are pyramid_beaker and dogpile.cache
pyramid_beaker was written to offer beaker caching for sessions. it also lets you configure beaker cache regions, which can be used elsewhere.
dogpile.cache is a replacement for beaker. it hasn't been integrated to offer session support or environment.ini based setup yet. however it addresses a lot of miscellaneous issues and shortcomings with beaker.
you can't/shouldn't cache a SqlAlchemy query or results. weird and bad things will happen, because the SqlAlchemy objects are bound to a database session. it's much better to convert the sqlalchemy results into another object/dict and cache those.