3- Explain how you would implement a caching strategy for a page that shows the most recent posts to reduce database load.
-
3.1- Explain fragment Caching
<table> <thead> <tr> <th>Title</th> <th>Description</th> <th>Image url</th> <th>Price</th> <th colspan="3"></th> </tr> </thead> <tbody> <% @products.each do |product| %> <%= render product %> <% end %> </tbody>
-
3.2- Explain Low-Level Caching
recent_posts = Rails.cache.fetch('recent_posts', expires_in: 10.minutes) do Post.order(created_at: :desc).limit(10).to_a end