How accurate is Cache Potential?

For example, when I run hugo --templateMetrics --templateMetricsHints, it shows a cache potential of 75% for my share buttons, but then defaults to only one post link when the file is partialCached i.e no matter the page, they all point to one link only which is different from the current page.

if the cache potential <100% you may want to call partialCached with VARIANT argument.

So, like {{- partialCached "post-share.html" . .Page }}? (Edit: This is incorrect. Doesn’t work)

Recommended reading:

I am already aware of the article, but in my example, the links are not the same but dynamic on every page. So, I am not sure which variant to use. I have other examples, e.g menu with .HasMenuCurrent and prev-next links, but I would like to tackle this first.

Show your social link partial. The cache potential is for the whole partial, not single links in it. You might have misunderstood what the potential is for.

{{- partialCached "post-share.html" . .Page }} should properly cache per page, but only if there is no caching going on in “post-share.html” itself. “They all point to one link” sounds like there is a second caching going on with individual links inside post-share.html.

Another source of issues could be, that the point where you have your partialCached call is within another context, so .Page is not the page you would expect. Try page instead, which is a “global” call to the .Page object.

But in general, this is the point where you probably should show some code to make sure people understand the real situation.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.