Merb_piece_cache 是一个小型的Ruby库,用以提供给 Merb 框架来缓存 HTML 片段。
示例代码:
<!-- rendered every time (because never cached) -->
<% if @user %>
Hello <%=h @user %>!
<% else %>
<a href="/login">Login</a>
<% end %>
<!-- rendered only when cache is expired or not found -->
<% lifetime = 5*60 # sec, default is nil(=infinity) %>
<% cache_with("members/index", lifetime) do %>
<ul>
<% for member in @members %>
<li><%=h @member.name %></li>
<% end %>
<ul>
<% end %>