tpl/transform: Include options in cache key

See #5555
This commit is contained in:
Bjørn Erik Pedersen 2018-12-23 21:34:17 +01:00
parent 62d031aedf
commit be58c7b9c8
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
2 changed files with 13 additions and 0 deletions

View file

@ -18,6 +18,7 @@ import (
"encoding/csv" "encoding/csv"
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings"
"github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/common/herrors"
@ -39,6 +40,14 @@ type Decoder struct {
Comment rune 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. // Default is a Decoder in its default configuration.
var Default = Decoder{ var Default = Decoder{
Delimiter: ',', Delimiter: ',',

View file

@ -62,6 +62,10 @@ func (ns *Namespace) Unmarshal(args ...interface{}) (interface{}, error) {
return nil, errors.New("no Key set in Resource") return nil, errors.New("no Key set in Resource")
} }
if decoder != metadecoders.Default {
key += decoder.OptionsKey()
}
return ns.cache.GetOrCreate(key, func() (interface{}, error) { return ns.cache.GetOrCreate(key, func() (interface{}, error) {
f := metadecoders.FormatFromMediaType(r.MediaType()) f := metadecoders.FormatFromMediaType(r.MediaType())
if f == "" { if f == "" {