简体   繁体   English

如何使用Pyramid缓存?

[英]How to cache using Pyramid?

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? 例如,如何缓存db查询(SQLAlchemy),如何缓存视图? Could anyone give some link to examples or documentation? 任何人都可以提供一些示例或文档的链接吗?

Appreciate any help! 感谢任何帮助!

EDITED: 编辑:

How to use memcache or database type cache or filebased cache? 如何使用memcache或数据库类型缓存或基于文件的缓存?

Your options are pyramid_beaker and dogpile.cache 你的选择是pyramid_beaker和dogpile.cache

pyramid_beaker was written to offer beaker caching for sessions. pyramid_beaker是为了为会话提供烧杯缓存而编写的。 it also lets you configure beaker cache regions, which can be used elsewhere. 它还允许您配置烧杯缓存区域,可以在别处使用。

dogpile.cache is a replacement for beaker. dogpile.cache是​​烧杯的替代品。 it hasn't been integrated to offer session support or environment.ini based setup yet. 它还没有集成到提供会话支持或基于environment.ini的设置。 however it addresses a lot of miscellaneous issues and shortcomings with beaker. 然而,它解决了烧杯的许多杂项问题和缺点。

you can't/shouldn't cache a SqlAlchemy query or results. 你不能/不应该缓存SqlAlchemy查询或结果。 weird and bad things will happen, because the SqlAlchemy objects are bound to a database session. 奇怪和坏事将会发生,因为SqlAlchemy对象绑定到数据库会话。 it's much better to convert the sqlalchemy results into another object/dict and cache those. 将sqlalchemy结果转换为另一个对象/字典并缓存它们会好得多。

You should install pyramid_beaker . 你应该安装pyramid_beaker

Then read the beaker documentation. 然后阅读烧杯文档。 By default it uses memory based cache, but it can easily support memcached and filebased cache. 默认情况下,它使用基于内存的缓存,但它可以轻松支持memcached和基于文件的缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM