我试图添加片段缓存以加快网站性能。现在,我在development
模式下测试了它,所以我改变了这个
#environments/developments.rb
config.action_controller.perform_caching = true
而在erb
<% @projects.each do |project| %>
<% cache project do %>
<%= link_to "#{project.name}", category_project_path(@category, project) %>
<br>
<% end %>
<% end %>
但是,它似乎不起作用。每次我刷新页面时,它都会在终端中再次显示查询。
我以为它只会在第一次查询一次,还是我误解了缓存的概念?
Processing by CategoriesController#show as HTML
Parameters: {"id"=>"3306"}
Category Load (0.4ms) SELECT "categories".* FROM "categories" WHERE "categories"."id" = $1 LIMIT 1 [["id", 3306]]
Project Load (0.5ms) SELECT "projects".* FROM "projects" WHERE "projects"."category_id" IN (3306)
(0.4ms) SELECT DISTINCT COUNT(DISTINCT "projects"."id") FROM "projects" WHERE "projects"."category_id" = $1 [["category_id", 3306]]
Project Load (1.0ms) SELECT DISTINCT "projects".* FROM "projects" WHERE "projects"."category_id" = $1 LIMIT 10 OFFSET 0 [["category_id", 3306]]
Cache digest for app/views/categories/show.html.erb: 9b54e2d9c7ce230e3f6a333f00d549da
Read fragment views/projects/3670-20160715055333331671000/9b54e2d9c7ce230e3f6a333f00d549da (0.2ms)
Cache digest for app/views/categories/show.html.erb: 9b54e2d9c7ce230e3f6a333f00d549da
Read fragment views/projects/3677-20160715055334439274000/9b54e2d9c7ce230e3f6a333f00d549da (0.2ms)
Cache digest for app/views/categories/show.html.erb: 9b54e2d9c7ce230e3f6a333f00d549da
Read fragment views/projects/3678-20160715055334446172000/9b54e2d9c7ce230e3f6a333f00d549da (0.2ms)
Cache digest for app/views/categories/show.html.erb: 9b54e2d9c7ce230e3f6a333f00d549da
Read fragment views/projects/3689-20160715055334536421000/9b54e2d9c7ce230e3f6a333f00d549da (0.1ms)
Rendered categories/show.html.erb within layouts/application (8.7ms)
Completed 200 OK in 31ms (Views: 26.0ms | ActiveRecord: 2.3ms)