Mongrel CACHE 日志条目,特别是 SQL 语句的 CACHE 条目
在查看 Mongrel 日志的过程中,我发现了一些我想要优化的 SQL 语句。在研究这些内容时,我注意到这些条目有时在它们前面有 CACHE,例如:
CACHE (0.0ms) SELECT * FROM `customers` WHERE (`customers`.`id` = 35)
考虑到执行时间,我假设 Mongrel 确实正在缓存这些数据。我的问题是这是如何配置的?我在网上找不到太多关于模型数据缓存的信息;我读过的大部分内容都与缓存静态页面或页面片段有关。我没有明确执行任何操作来启用此缓存,因此我实际上只是在寻找有关其配置方式及其工作方式的指针。提前致谢!
In the process of looking at my logs from Mongrel, I found some SQL statements that I wanted to optimize. While looking into these, I noticed that these entries sometimes have CACHE in front of them, e.g.:
CACHE (0.0ms) SELECT * FROM `customers` WHERE (`customers`.`id` = 35)
Given the execution time, I'm assuming Mongrel really is caching this data. My question is how is this configured? I haven't been able to find much online about caching of model data; most of what I've read has to do with caching static pages or page fragments. I haven't done anything explicitly to enable this caching, so I'm really just looking for a pointer on how it's configured and how it works. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
其实和杂种没有什么关系。默认情况下,Rails 围绕每个控制器操作执行一个
ActiveRecord::Base.cache
。这意味着在该操作的范围内,它将缓存查询结果并提供缓存中的结果,而不是再次访问数据库。您应该在日志的较高位置看到一个相同的查询(在同一操作内),该查询没有以 CACHE 为前缀,这是已存储结果的原始查询。更多详细信息请参见此处。
It isn't actually anything to do with mongrel. Rails does a
ActiveRecord::Base.cache
around every controller action by default. This means that in the scope of that action it will cache the results of queries and provide the results from the cache rather than hitting the database again. You should see an identical query higher in the log (within the same action) that is not prefixed with CACHE which is the original query for which the results have been stored.Some more details here.