Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PartialCached variant #1368

Closed
bep opened this issue Aug 21, 2015 · 5 comments
Closed

Add PartialCached variant #1368

bep opened this issue Aug 21, 2015 · 5 comments
Assignees
Milestone

Comments

@bep
Copy link
Member

bep commented Aug 21, 2015

See

http://discuss.gohugo.io/t/how-to-make-hugo-faster/1597/6

{{ range $.Site.Pages.ByTitle }}
  {{ if and (in .Params.categories "Category") (in .Params.categories "sub-category") }}
    <li><a href="{{ .Permalink }}">{{ .Title }}</a>
        {{ if .Draft }} * {{ end }}</li>
  {{ end }}
{{ end }}

The above is an extract of a partial used on every page. It is an ineffective construct (slightly better in 0.15, I guess) and it gets really bad when page count goes up.

But it's static. And, although it is impossible to make a general assumption about how "cacheable" a given partial is (I think?), the user will know -- and should be able to say so.

So, for a site with 2000 pages, the above should only be needed to be processed once.

@tatsushid not sure how Ace include works in this area?

@tatsushid
Copy link
Contributor

@bep, Ace parses a template file every time when the ParseSource and CompileResult or CompileResultWithTemplate are called. include is parsed when a base template file is read and is later (compile time) replaced by {{ template "template_name" pipeline }}. So using include is the same using template directly.

Ace caches parsed template files with these template names in a hash and if it finds a name in the hash, it bypasses parsing the template file, just returns a compile result which is a HTML file with Go template syntax.

But this cache mechanism is only implemented in ace.Load function. Hugo doesn't use it to merge all templates and use custom template function. So, instead of using Load, Hugo emulates the function without any cache mechanisms.

Anyway, Ace doesn't cache any rendering results. It just caches compiled result if Load is used. Executing template with values is needed.

@tatsushid
Copy link
Contributor

Partial is used in both rendering with page specific values and rendering with common values to whole site. There is no way to know that at rendering time but only know a template author so introducing something "partial with cache" function is a reasonable way I think.

@bep bep changed the title Add caching option to Partial Add PartialCached variant Aug 22, 2015
@LiaungYip
Copy link
Contributor

I think the good people at Camunda are maintaining a version of Hugo with cached partials.

There was some discussion about submitting a PR to get that functionality into main.

See:

https://github.com/camunda-third-party/hugo/tree/camunda

particularly camunda-third-party@e15f8f5 :

feat(tpl): add cachedPartial template function
- allows to specify that a partial should be cached after first
  evaluation, useful for static complex partials often used partials

https://app.camunda.com/jira/browse/CAM-6005

https://app.camunda.com/jira/browse/CAM-6385

LiaungYip referenced this issue in camunda-third-party/hugo Aug 8, 2016
- allows to specify that a partial should be cached after first
  evaluation, useful for static complex partials often used partials
@bep bep added this to the v0.18 milestone Oct 10, 2016
@bep
Copy link
Member Author

bep commented Oct 10, 2016

Suggested API:

partialCached(name string, context interface{}, variant ...string) template.HTML
  • Cache key constructed from name + (optional) variant
  • Note that this will be called from multiple threads, so need a rw mutex

moorereason added a commit to moorereason/hugo that referenced this issue Oct 11, 2016
Supports an optional variant string parameter so that a given partial
will be cached based upon the name+variant.

Fixes gohugoio#1368
@bep bep closed this as completed in 474eb45 Oct 11, 2016
tychoish pushed a commit to tychoish/hugo that referenced this issue Aug 13, 2017
Supports an optional variant string parameter so that a given partial
will be cached based upon the name+variant.

Fixes gohugoio#1368
Closes gohugoio#2552
@github-actions
Copy link

github-actions bot commented Apr 1, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants