tpl/transform: Include options in cache key - hugo - [fork] hugo port for 9front
HTML git clone git@git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
DIR commit be58c7b9c88116094ca2b424c77210ddcccfff8e
DIR parent 62d031aedfc128729b460241bd99d97b5d902e62
HTML Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date: Sun, 23 Dec 2018 21:34:17 +0100
tpl/transform: Include options in cache key
See #5555
Diffstat:
M parser/metadecoders/decoder.go | 9 +++++++++
M tpl/transform/unmarshal.go | 4 ++++
2 files changed, 13 insertions(+), 0 deletions(-)
---
DIR diff --git a/parser/metadecoders/decoder.go b/parser/metadecoders/decoder.go
@@ -18,6 +18,7 @@ import (
"encoding/csv"
"encoding/json"
"fmt"
+ "strings"
"github.com/gohugoio/hugo/common/herrors"
@@ -39,6 +40,14 @@ type Decoder struct {
Comment rune
}
+// OptionsKey is used in cache keys.
+func (d Decoder) OptionsKey() string {
+ var sb strings.Builder
+ sb.WriteRune(d.Delimiter)
+ sb.WriteRune(d.Comment)
+ return sb.String()
+}
+
// Default is a Decoder in its default configuration.
var Default = Decoder{
Delimiter: ',',
DIR diff --git a/tpl/transform/unmarshal.go b/tpl/transform/unmarshal.go
@@ -62,6 +62,10 @@ func (ns *Namespace) Unmarshal(args ...interface{}) (interface{}, error) {
return nil, errors.New("no Key set in Resource")
}
+ if decoder != metadecoders.Default {
+ key += decoder.OptionsKey()
+ }
+
return ns.cache.GetOrCreate(key, func() (interface{}, error) {
f := metadecoders.FormatFromMediaType(r.MediaType())
if f == "" {