hugo/content/functions/partialCached.md
Bjørn Erik Pedersen dae5a7c61c Squashed 'docs/' changes from 36d7e22f5..000ab7c42
000ab7c42 Fix `ref` and `relref` shortcode usage patterns
4e7123d20 Add som code fence lang tags
21d4f97d1 Update homepage for ox-hugo tool
668969fc4 Remove superflous back ticks
f78cf6490 Fix code example
05aaee8ce Remove background color from code shortcode
dcb0998d0 Add a Build Performance page draft
50e04593a Document templateMetrics usage
67ad36691 Merge commit 'f66d59b8991c264c3366895b5e148ea810a184cd'
f66d59b89 Squashed 'themes/gohugoioTheme/' changes from ca53082d..cdaa89c8

git-subtree-dir: docs
git-subtree-split: 000ab7c423341bb215d4ccb4a9e54d3d64957e24
2017-10-04 09:27:29 +02:00

40 lines
1.4 KiB
Markdown

---
title: partialCached
linktitle: partialCached
description: Allows for caching of partials that do not need to be re-rendered on every invocation.
godocref:
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-01
categories: [functions]
menu:
docs:
parent: "functions"
keywords: [performance]
signature: ["partialCached LAYOUT INPUT [VARIANT...]"]
workson: []
hugoversion:
relatedfuncs: []
deprecated: false
aliases: []
---
The `partialCached` template function can offer significant performance gains for complex templates that don't need to be re-rendered on every invocation. Here is the simplest usage:
```
{{ partialCached "footer.html" . }}
```
You can also pass additional parameters to `partialCached` to create *variants* of the cached partial. 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:
{{< code file="partial-cached-example.html" >}}
{{ partialCached "footer.html" . .Section }}
{{< /code >}}
If you need to pass additional parameters to create unique variants, you can pass as many variant parameters as you need:
```
{{ partialCached "footer.html" . .Params.country .Params.province }}
```
Note that the variant parameters are not made available to the underlying partial template. They are only use to create a unique cache key.