Fragment caching in Rails

For these examples we're going to assume there is a Post class and a PostsController with all of its actions and views for the seven restful routes.

Types of caches in rails

Single partial caching

<% @posts.each do |post| %>
  <% cache post do %>
		<%= render post %>
	<% end %>
<% end %>

Collection caching

<%= render partial: 'post', collection: @posts, cache: true %>

Project objective

Version 1 of component caching aims at supporting the cache method for single partial caching.

https://github.com/rails/rails/blob/master/actionview/lib/action_view/template/resolver.rb

Tests

Control

Let Rails cache normally

The cache should expire when updated_at in each post changes or when the partial changes its html content.

Control