Caching SQLAlchemy支持缓存吗?

Caching SQLAlchemy支持缓存吗?,caching,sqlalchemy,cherrypy,Caching,Sqlalchemy,Cherrypy,SQLAlchemy是否支持某种缓存,因此如果重复运行同一查询,它将从缓存返回响应,而不是查询数据库?数据库更新时是否自动清除此缓存 或者在CherryPy+SQLAlchemy设置上实现此功能的最佳方法是什么?不是对第二个问题的回答,但从该链接中的注释可以看出SQLAlchemy不支持缓存: 乌鸦说… 乔纳森·埃利斯说…… 或者通过弱引用dicts(weakref.WeakValueDictionary)使用应用程序级缓存,请参见此处的示例:在0.6中,我们有一个非常全面的缓存解决方案,例如与

SQLAlchemy是否支持某种缓存,因此如果重复运行同一查询,它将从缓存返回响应,而不是查询数据库?数据库更新时是否自动清除此缓存


或者在CherryPy+SQLAlchemy设置上实现此功能的最佳方法是什么?

不是对第二个问题的回答,但从该链接中的注释可以看出SQLAlchemy不支持缓存:

乌鸦说…

乔纳森·埃利斯说……


或者通过弱引用dicts(weakref.WeakValueDictionary)使用应用程序级缓存,请参见此处的示例:

在0.6中,我们有一个非常全面的缓存解决方案,例如与嵌入式挂钩结合使用。这是一个将查询子类化的方法,使其了解Beaker,并允许通过查询选项控制显式查询的查询缓存以及惰性加载程序

我现在正在生产中运行它。示例本身在dist中,介绍文档位于


更新:烧杯现在已被
dogpile
caching:

SQLAlchemy支持两种类型的缓存:

  • 缓存结果集,以便重复运行同一查询时命中缓存而不是数据库。它使用支持许多不同后端的
    dogpile
    ,包括
    memcached
    redis
    和基本平面文件

    文件如下:

  • 缓存
    query
    对象,这样Python解释器就不必每次都手动重新组装查询字符串。这些查询称为
    baked查询
    ,缓存称为
    baked
    。基本上,它在访问数据库之前缓存了
    sqlalchemy
    执行的所有操作——它不会减少数据库调用。初始基准测试显示,在代码冗余度略有增加的情况下,
    query
    生成时间的加速率高达40%

    文件如下:


  • 此链接建议/显示后续查询不使用查询,而是从标识映射返回实例,但这仅在使用主键进行查询时有效。结果集的缓存是否不使用标识映射?在这种情况下,我第一次听说狗堆。或者它与身份地图有什么关系?
    Does SQLAlchemy do any kind of internal caching?
    
    For example, if you ask for the same data twice (or an obvious subset
    of the initially requested data) will the database be hit once or twice?
    
    I recently wrote a caching database abstraction layer for an
    application and (while fun) it was a fair bit of work to get it to a
    minimally functional state. If SQLAlchemy did that I would seriously
    consider jumping on the bandwagon.
    
    I've found things in the docs that imply something like this might be
    going on, but nothing explicit.
    4:36 PM
    
    No; the author of SA [rightly, IMO] considers caching a separate concern.
    
    What you saw in the docs is probably the SA identity map, which makes it so 
    if you load an instance in  two different places, they will refer
    to the same object. But the database will still be queried twice, so it is
    not a cache in the sense you mean.