forked from gohugoio/hugo
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
2 changed files
with
12 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e15f8f5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a feature request open for this on the main Hugo project - see:
A PR might be well received!
e15f8f5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I known but this is more like a hack and I wasn't comfortable to submit it upstream. Also I probably miss some go knowledge on how to do this in a proper way. Maybe if I have some spare time I will try to submit something useful.
e15f8f5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@menski,
I suspect that your solution is susceptible to race conditions. You need to protect the map accesses with a mutex. Have a look at the regexpCache type to see how I handled a similar situation when trying to cache regular expression objects.
Another addition that would help get this accepted upstream is to add some simple unit tests.
e15f8f5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tips. I will have a look at the regex cache.