Result of ActiveRecord Rails Cache

My current homepage displays all available categories and the total number of posts in each category. This, of course, has a performance hit on the website, and I'm just wondering if it is possible to cache at all?

I do not mind if the cache is a little outdated and if the number of messages does not correspond to 100% with each update, but I would like it to execute only every 30 minutes.

+4
source share
2 answers

In Rails, you can cache almost everything.

You can cache partial or requests. And you can also finish them manually.

for instance

cache('categorylist') do
     render partial: 'such'
end

post.rb reset

after_create {
    Rails.cache.delete('categorylist')
}

, ( ) . .

+1

ActiveRecord , . . - Fragment Caching, rails docs, : http://edgeguides.rubyonrails.org/caching_with_rails.html

, , , ( , ):

<% @products.each do |product| %>
  <% cache product do %>
    <%= render product %>
  <% end %>
<% end %>

/. updated_at , .

, html, .

0

Source: https://habr.com/ru/post/1664806/


All Articles