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.

Revisions

  1. yigitbacakoglu created this gist Jun 7, 2024.
    33 changes: 33 additions & 0 deletions 3.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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>
    </table>
    - 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
    ```
    ---