-
Hello there, It's me again, looking for more guidance. This time, it's related to build performance/cache. I added a sidebar to every single page that lists ten random featured articles, all pages should list the same 10 random articles, but update them everytime that I re-build the website. These are the related (simplified) files: <!-- _layouts/default.erb -->
<body>
<main>
<%= yield %>
</main>
<%= render 'sidebar_random_articles' %>
</body> and that partial looks like this: <!-- _partials/sidebar_random_articles.erb -->
<aside>
<% site.collections.articles.resources.select{|s| s.data[:trending] == true}.shuffle(random: Random.new(Date.today.day)).first(10).each do |article| %>
<div><%= article.data.title %></div>
<% end %>
</aside> It works totally fine, but it now takes like 50 seconds to build the website (everytime I change something in the code). If I remove that partial, the build takes like 5 seconds. Do you think is there a way to use the Cache API here in the templates? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 11 replies
-
Hey @luctus, I'd recommend extracting the logic to generate the random articles into a Perhaps the builder could add a list of articles to
Does that make sense? |
Beta Was this translation helpful? Give feedback.
Hey @luctus, I'd recommend extracting the logic to generate the random articles into a
Builder
class and then use that to cache it or maybe even just hold it in memory as it only needs to last for the duration of the build.Perhaps the builder could add a list of articles to
site.data
and in your template you could do something like:Does that make sense?