Skip to content

Instantly share code, notes, and snippets.

@yigitbacakoglu
Created June 7, 2024 13:28
Show Gist options
  • Select an option

  • Save yigitbacakoglu/8b4bb770cc3251e79b52922a3b5bddb9 to your computer and use it in GitHub Desktop.

Select an option

Save yigitbacakoglu/8b4bb770cc3251e79b52922a3b5bddb9 to your computer and use it in GitHub Desktop.

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
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment