[英]Rails fragment caching slower?
I'm trying to implement fragment caching in Rails. 我正在尝试在Rails中实现片段缓存。 Without caching, code looks like this:
没有缓存,代码如下所示:
<div>
<% data = MyObject.getDataFromDataBase %>
<!-- complicated divs displaying the 'data', multiple partials -->
</div>
It creates a lot of SQL queries (in the view) and, in overall, takes around: 它创建了许多SQL查询(在视图中),并且总体上涉及:
Completed 200 OK in 1107ms (Views: 1007.0ms | ActiveRecord: 93.6ms)
After wrapping this up with cache like this: 用缓存将其包装后,如下所示:
<div>
<% cache 'my_cached' do %>
<% data = MyObject.getDataFromDataBase %>
<!-- complicated divs displaying the 'data', multiple partials -->
<% end %>
</div>
I see the output (on the second refresh) - NO SQL queries (besides user role check), nothing, just: 我看到了输出(第二次刷新)-没有SQL查询(除了用户角色检查),什么也没有:
Read fragment views/my_cached/bda6867d8a08ec1637c0c926edced2d2 (0.7ms)
Completed 200 OK in 1241ms (Views: 1228.7ms | ActiveRecord: 6.8ms)
And my questions is: How its possible, that AFTER caching it takes longer? 我的问题是: 缓存之后需要更长的时间怎么可能? Nothing happens in the logs, file is loaded in 0.7 ms, why it takes over 1 second overall?
日志中什么也没有发生,文件在0.7毫秒内加载完毕,为什么整个过程要花费1秒钟以上?
Caching works correctly. 缓存工作正常。
I've used mini profiler to see how rendering works and my page refreshes faster - from 160 ms to around 10 ms. 我使用了微型探查器来查看渲染的工作原理以及页面刷新的速度-从160毫秒到10毫秒左右。 The problem was development mode and application.html.erb file, with loading time around 1 second.
问题是开发模式和application.html.erb文件,加载时间约为1秒。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.