Permalink
Browse files

tpl/transform: Include options in cache key

See #5555
  • Loading branch information...
bep committed Dec 23, 2018
1 parent 62d031a commit be58c7b9c88116094ca2b424c77210ddcccfff8e
Showing with 13 additions and 0 deletions.
  1. +9 −0 parser/metadecoders/decoder.go
  2. +4 −0 tpl/transform/unmarshal.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: ',',
@@ -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 == "" {

0 comments on commit be58c7b

Please sign in to comment.