Partial Template Cache best practices

<%- if @topic_view.topic.tags.present? %>
<%= t 'js.tagging.tags' %>: <%- @topic_view.topic.tags.each do |t| %> <%= t %> <%- end %>
<% end %>

Greetings everyone.

The CMS Squad just rolled out some updates for the Partial Template Caching documentation.
Particularly, we’ve made a separate doc explaining the template tag mechanics in depth and refined the performance recommendations.

Some important new recommendations are:

  1. Always use cache conditionals whenever possible
  2. Avoid heavy computations in cache keys and conditionals
  3. Tune the cache backend settings

Another recommendation which is not included to the CMS documentation:

  • DO NOT cache Elemental Area. Consider caching every separate block instead (where it is appropriate). Especially if you have silverstripe/userforms installed. User data may be leaked through the cache, which is a potential security issue.

If we missed something interesting, please share your recommendations in this thread, or consider making a PR for the CMS documentation:

2 Likes

Hi,

A couple of questions / comments on the first doc:

The title for this section: silverstripe-framework/11_Partial_Template_Caching.md at 4 · silverstripe/silverstripe-framework · GitHub

Says ‘nesting in For and If…’ then goes on to talk about <% if … %> and <% loop … %> blocks. It’s a little confusing.


Updating the default cache time is a question that comes up quite often. I think a short example snippet to reinforce the information here (silverstripe-framework/11_Partial_Template_Caching.md at 4 · silverstripe/silverstripe-framework · GitHub) would be nice.


I’m happy to PR either / both of the above if it helps.

1 Like

I’m happy to PR either / both of the above if it helps.

Yes please! PRs are always much appreciated :slight_smile: