partialCached.md (1773B)
1 ---
2 title: partialCached
3 linktitle: partialCached
4 description: Allows for caching of partials that do not need to be re-rendered on every invocation.
5 date: 2017-02-01
6 publishdate: 2017-02-01
7 lastmod: 2017-02-01
8 categories: [functions]
9 menu:
10 docs:
11 parent: "functions"
12 keywords: [performance]
13 signature: ["partialCached LAYOUT INPUT [VARIANT...]"]
14 workson: []
15 hugoversion:
16 relatedfuncs: []
17 deprecated: false
18 aliases: []
19 ---
20
21 The `partialCached` template function can offer significant performance gains for complex templates that don't need to be re-rendered on every invocation.
22
23 **Note:** Each Site (or language) has its own `partialCached` cache, so each site will execute a partial once.
24
25 Here is the simplest usage:
26
27 ```
28 {{ partialCached "footer.html" . }}
29 ```
30
31 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:
32
33 {{< code file="partial-cached-example.html" >}}
34 {{ partialCached "footer.html" . .Section }}
35 {{< /code >}}
36
37 If you need to pass additional parameters to create unique variants, you can pass as many variant parameters as you need:
38
39 ```
40 {{ partialCached "footer.html" . .Params.country .Params.province }}
41 ```
42
43 Note that the variant parameters are not made available to the underlying partial template. They are only use to create a unique cache key. Since Hugo `0.61.0` you can use any object as cache key(s), not just strings.
44
45
46 > See also the [The Full Partial Series Part 1: Caching!](https://regisphilibert.com/blog/2019/12/hugo-partial-series-part-1-caching-with-partialcached/)