partialCached generates the partial once per language

Hi all !

I have an issue when using partialCached.

I would expect partialCached templates used without variant to be generated only once per build.

However, for my project, in multilanguage mode, it seems that the templates are generated once per language.

Here is my config file :

{
    "disablePathToLower": "true",
    "defaultContentLanguage": "en",
    "defaultContentLanguageInSubdir": "true",
    "disableHugoGeneratorInject": "true",
    "hasCJKLanguage": "true",
    "uglyURLS": "true",
    "disableKinds": [
        "RSS", "taxonomy"
      ],
    "languages": {
        "de": {
            "contentDir": "content/de",
            "languageName": "Deutsch",
            "url" : "/de/",
            "languageCode": "de",
            "weight": 1
         },
         "en": {
            "contentDir": "content/en",
            "languageName": "English",
            "url": "/en/",
            "languageCode": "en",
            "weight": 2
         },
         "es": {
            "contentDir": "content/es",
            "languageName": "Español",
            "url" : "/es/",
            "languageCode": "es",
            "weight": 3
         },
         "fr": {
            "contentDir": "content/fr",
            "languageName": "Français",
            "url": "/fr/",
            "languageCode": "fr",
            "weight": 4
         }
     },
     "sitemap": {
        "changefreq": "hourly",
        "priority": 0.5
     },
     "taxonomies": {
         "category": "",
         "tag": ""
     }
}

Log sample

hugo --templateMetrics 
Building sites … 
Template Metrics:

     cumulative       average       maximum         
       duration      duration      duration  count  template
     ----------      --------      --------  -----  --------
   924.236099ms   11.552951ms   39.807078ms     4  partials/player-data.html

I would expect player-data.html to be generated only once…

Thanks in advance for your help !

Why? I would expect that it to be like it is today.

To be a little longer: I understand where you are coming from, and I’m open to changing this, if some good arguments can be put out there. The thing is, a language is its own site with its own state (language bundles etc.), and I have alway thought about the “partial cache” as a way to make it faster – not as a way to make it run once. Which is not usually a guarantee that caches make.

1 Like

Thanks for your reply ! In fact, I assumed the cached partials were generated only once after reading the documentation :

For example, if you have a complex partial that should be identical when rendered for pages within the same section, you could use a variant based upon section so that the partial is only rendered once per section

Actually, I am really impressed by the feature. It is really helpfuI for sections that take a lot of time to generate and do not change across websites.

Now, I understand how it works behind the scenes and that the cache may be purged sometimes.

What about a parameter to define the cache size ?

It’s never purged – but you got 1 cache per Site (language) – I guess is the answer.

To add to the above,if you add a partial that contained:

{{ i18n "hello" }}

I think people would be really surprised if partialCached made it “Hello” in all languages.

If you add {{ i18n "hello" }} in a partialCached partial, then you must use the language as a variant to make it work, as described in the documentation. Same for all the partials that need a context. I think the documentation is pretty clear on the subject and people won’t be surprised.

Actually, I use the partialCached feature for all the time-consuming partials of my project. The partials are split into generic partials and language-specific partials - the language is passed as a variant when necessary.

I think it makes sense to use the language as a variant, and have 1 cache per project.

No, that is not clear. I would be really, really surprised. And I know more Hugo than anyone.

1 Like

OK. I probably misunderstood the documentation then. You can close the topic if you wish.

I will check the documentation later. Not sure what that says.

Created a docs issue for this. The partialCached functionality may have pre-dated the i18n features. Docs just need to be clarified.

1 Like